home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / MNBanner.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.5 KB  |  408 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.    MNBanner.cpp -- implementation for the MNBanner funky little pseudo title bar proxy icon thingy.
  20.    Created: Chris Toshok <toshok@netscape.com>, 15-Oct-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "MNBanner.h"
  26. #include "Logo.h"
  27.  
  28. #include <Xm/Frame.h>
  29. #include <Xm/Form.h>
  30. #include <Xm/Label.h>
  31. #include <Xm/ArrowB.h>
  32.  
  33. #include <Xfe/ToolItem.h>
  34. #include "ThreePaneView.h"
  35.  
  36. const char *XFE_MNBanner::twoPaneView = "XFE_MNBanner::twoPaneView";
  37. XFE_MNBanner::XFE_MNBanner(XFE_Frame *parent_frame,
  38.                            XFE_Toolbox * parent_toolbox,
  39.                            char *title, char *subtitle,
  40.                            char *info) 
  41.     : XFE_ToolboxItem(parent_frame,parent_toolbox)
  42. {
  43.   Widget tool_item;
  44.  
  45.   m_parentFrame = parent_frame;
  46.  
  47.   // Create the base widget - a tool item
  48.   tool_item = XtVaCreateWidget("bannerItem",
  49.                                xfeToolItemWidgetClass,
  50.                                parent_toolbox->getBaseWidget(),
  51.                                XmNuserData,                this,
  52.                                NULL);
  53.     
  54.   m_form = XtVaCreateManagedWidget("banner",
  55.                                    xmFormWidgetClass,
  56.                                    tool_item,
  57.                                    NULL);
  58.   
  59.   // no proxy icon yet -- you must call setProxyIcon.
  60.   
  61.   m_titlelabel = XtVaCreateManagedWidget("title",
  62.                                          xmLabelWidgetClass,
  63.                                          m_form,
  64.                                          XmNleftAttachment, XmATTACH_FORM,
  65.                                          XmNrightAttachment, XmATTACH_NONE,
  66.                                          XmNtopAttachment, XmATTACH_FORM,
  67.                                          XmNbottomAttachment, XmATTACH_FORM,
  68.                                          NULL);
  69.  
  70.   m_subtitlelabel = XtVaCreateManagedWidget("subtitle",
  71.                                             xmLabelWidgetClass,
  72.                                             m_form,
  73.                                             XmNleftAttachment, XmATTACH_WIDGET,
  74.                                             XmNleftWidget, m_titlelabel,
  75.                                             XmNrightAttachment, XmATTACH_NONE,
  76.                                             XmNtopAttachment, XmATTACH_FORM,
  77.                                             XmNbottomAttachment, XmATTACH_FORM,
  78.                                             NULL);
  79.  
  80.   m_infolabel = XtVaCreateManagedWidget("info",
  81.                                         xmLabelWidgetClass,
  82.                                         m_form,
  83.                                         XmNalignment, XmALIGNMENT_END,
  84.                                         XmNleftAttachment, XmATTACH_WIDGET,
  85.                                         XmNleftWidget, m_subtitlelabel,
  86.                                         XmNrightAttachment, XmATTACH_FORM,
  87.                                         XmNtopAttachment, XmATTACH_FORM,
  88.                                         XmNbottomAttachment, XmATTACH_FORM,
  89.                                         NULL);
  90.  
  91.   // Register banner widgets for dragging
  92.   addDragWidget(m_form);
  93.   addDragWidget(m_titlelabel);
  94.   addDragWidget(m_subtitlelabel);
  95.   addDragWidget(m_infolabel);
  96.  
  97.   // Create the logo
  98.   m_logo = new XFE_Logo(m_parentFrame,tool_item,"logo");
  99.  
  100.   // It will always be small for this component
  101.   m_logo->setSize(XFE_ANIMATION_SMALL);
  102.                                         
  103.   setBaseWidget(tool_item);
  104.  
  105.   m_proxyicon = NULL;
  106.   m_mommyButton = NULL;
  107.   m_titleComponent = NULL;
  108.   m_arrowButton = NULL;
  109.  
  110.   setTitle(title);
  111.   setSubtitle(subtitle);
  112.   setInfo(info);
  113. }
  114.  
  115. void
  116. XFE_MNBanner::setMommyIcon(IconGroup *icons)
  117. {
  118.     if (!m_mommyButton) {
  119.         m_mommyButton = new XFE_Button(m_parentFrame,
  120.                                        m_form, 
  121.                                        "mommy", 
  122.                                        icons);
  123.         // 
  124.         m_mommyButton->setToplevel(m_parentFrame);
  125.  
  126.     }/* if */
  127.     else
  128.         m_mommyButton->setPixmap(icons); // XXX 
  129.  
  130.     XtVaSetValues(m_mommyButton->getBaseWidget(),
  131.                   XmNleftAttachment, XmATTACH_NONE,
  132.                   XmNrightAttachment, XmATTACH_FORM,
  133.                   XmNtopAttachment, XmATTACH_NONE,
  134.                   XmNbottomAttachment, XmATTACH_NONE,
  135.                   NULL);
  136.  
  137.     XtVaSetValues(m_infolabel,
  138.                   XmNleftAttachment, XmATTACH_WIDGET,
  139.                   XmNleftWidget, m_subtitlelabel,
  140.                   XmNrightAttachment, XmATTACH_WIDGET,
  141.                   XmNrightWidget, m_mommyButton->getBaseWidget(),
  142.                   XmNtopAttachment, XmATTACH_FORM,
  143.                   XmNbottomAttachment, XmATTACH_FORM,
  144.                   NULL);
  145.  
  146.     m_mommyButton->show();
  147.  
  148.     m_mommyButton->registerInterest(XFE_Button::doCommandCallback,
  149.                                     this,
  150.                                     (XFE_FunctionNotification)doMommyCommand_cb);
  151. }
  152.  
  153. XFE_CALLBACK_DEFN(XFE_MNBanner, doMommyCommand)(XFE_NotificationCenter *,
  154.                                                 void *,
  155.                                                 void *)
  156. {
  157.     m_parentFrame->doCommand(xfeCmdMommy);
  158. }
  159.  
  160. void
  161. XFE_MNBanner::showFolderBtn()
  162. {
  163.   getToplevel()->notifyInterested(XFE_MNBanner::twoPaneView);
  164. }
  165.  
  166. void
  167. showFolderBtnCB(Widget w, XtPointer clientData, XtPointer)
  168. {
  169.   XFE_MNBanner *obj = (XFE_MNBanner*)clientData;
  170.   unsigned char arrowDir;
  171.  
  172.   XtVaGetValues(w, XmNarrowDirection, &arrowDir, NULL);
  173.   if ( arrowDir == XmARROW_DOWN) 
  174.     XtVaSetValues(w, XmNarrowDirection, XmARROW_RIGHT, NULL);
  175.   else
  176.     XtVaSetValues(w, XmNarrowDirection, XmARROW_DOWN, NULL);
  177.  
  178.   obj->showFolderBtn();
  179. }
  180.  
  181. void 
  182. XFE_MNBanner::setProxyIcon(fe_icon *icon)
  183. {
  184.     Widget title_widget;
  185.  
  186.  
  187.     if (!m_proxyicon)
  188.         m_proxyicon = new XFE_ProxyIcon(m_toplevel, m_form, "mnProxy", icon);
  189.     else
  190.         m_proxyicon->setIcon(icon);
  191.     
  192. #if 0
  193.     XtVaSetValues(m_proxyicon->getBaseWidget(),
  194.                   XmNleftAttachment, XmATTACH_FORM,
  195.                   XmNrightAttachment, XmATTACH_NONE,
  196.                   XmNtopAttachment, XmATTACH_FORM,
  197.                   XmNbottomAttachment, XmATTACH_FORM,
  198.                   NULL);
  199. #endif
  200.     XtVaSetValues(m_proxyicon->getBaseWidget(),
  201.                   XmNleftAttachment, XmATTACH_WIDGET,
  202.                   XmNleftWidget, m_arrowButton,
  203.                   XmNrightAttachment, XmATTACH_NONE,
  204.                   XmNtopAttachment, XmATTACH_FORM,
  205.                   XmNbottomAttachment, XmATTACH_FORM,
  206.                   NULL);
  207.     
  208.     if (m_titleComponent)
  209.         title_widget = m_titleComponent->getBaseWidget();
  210.     else
  211.         title_widget = m_titlelabel;
  212.     
  213.     XtVaSetValues(title_widget,
  214.                   XmNleftAttachment, XmATTACH_WIDGET,
  215.                   XmNleftWidget, m_proxyicon->getBaseWidget(),
  216.                   XmNrightAttachment, XmATTACH_NONE,
  217.                   XmNtopAttachment, XmATTACH_FORM,
  218.                   XmNbottomAttachment, XmATTACH_FORM,
  219.                   NULL);
  220.     
  221.     m_proxyicon->show();
  222. }
  223.  
  224. void
  225. XFE_MNBanner::setTitle(char *title)
  226. {
  227.   XmString xmstr;
  228.  
  229.   if (m_titleComponent) // we can't possibly support this in an intelligent way.
  230.       return;
  231.  
  232.   if (title == NULL)
  233.       title = " ";
  234.  
  235.   xmstr = XmStringCreate(title, XmFONTLIST_DEFAULT_TAG);
  236.  
  237.   XtVaSetValues(m_titlelabel,
  238.                 XmNlabelString, xmstr,
  239.                 NULL);
  240.  
  241.   XmStringFree(xmstr);
  242. }
  243.  
  244. void
  245. XFE_MNBanner::setTitleComponent(XFE_Component *title_component)
  246. {
  247.     XtUnmanageChild(m_titlelabel);
  248.  
  249.     m_titleComponent = title_component;
  250.  
  251.     XtVaSetValues(m_titleComponent->getBaseWidget(),
  252.                   XmNleftAttachment, m_proxyicon ? XmATTACH_WIDGET : XmATTACH_FORM,
  253.                   XmNleftWidget, m_proxyicon ? m_proxyicon->getBaseWidget() : NULL,
  254.                   XmNrightAttachment, XmATTACH_NONE,
  255.                   XmNtopAttachment, XmATTACH_FORM,
  256.                   XmNbottomAttachment, XmATTACH_FORM,
  257.                   NULL);
  258.  
  259.     XtVaSetValues(m_subtitlelabel,
  260.                   XmNleftAttachment, XmATTACH_WIDGET,
  261.                   XmNleftWidget, m_titleComponent->getBaseWidget(),
  262.                   XmNrightAttachment, XmATTACH_NONE,
  263.                   XmNtopAttachment, XmATTACH_FORM,
  264.                   XmNbottomAttachment, XmATTACH_FORM,
  265.                   NULL);
  266.  
  267.     m_titleComponent->show();
  268. }
  269.  
  270. void
  271. XFE_MNBanner::setSubtitle(char *subtitle)
  272. {
  273.   XmString xmstr;
  274.  
  275.   if (subtitle == NULL)
  276.       subtitle = " ";
  277.  
  278.   xmstr = XmStringCreate(subtitle, XmFONTLIST_DEFAULT_TAG);
  279.  
  280.   XtVaSetValues(m_subtitlelabel,
  281.         XmNlabelString, xmstr,
  282.         NULL);
  283.  
  284.   XmStringFree(xmstr);
  285. }
  286.  
  287. void
  288. XFE_MNBanner::setInfo(char *info)
  289. {
  290.     XmString xmstr;
  291.     XmString old_info;
  292.     XP_Bool needsChange = TRUE;
  293.     char *oldinfoStr = NULL;
  294.  
  295.     if (info == NULL)
  296.         info = " ";
  297.  
  298.     XtVaGetValues (m_infolabel, 
  299.                    XmNlabelString, &old_info,
  300.                    NULL);
  301.  
  302.     if (XmStringGetLtoR(old_info, XmFONTLIST_DEFAULT_TAG, &oldinfoStr))
  303.         if (oldinfoStr && !strcmp(oldinfoStr, info))
  304.             {
  305.                 needsChange = FALSE;
  306.                 if (oldinfoStr) XtFree(oldinfoStr);
  307.             }
  308.     
  309.     if (needsChange)
  310.         {
  311.             xmstr = XmStringCreate(info, XmFONTLIST_DEFAULT_TAG);
  312.             
  313.             XtVaSetValues(m_infolabel,
  314.                           XmNlabelString, xmstr,
  315.                           NULL);
  316.             
  317.             XmStringFree(xmstr);
  318.         }
  319. }
  320.  
  321. Widget
  322. XFE_MNBanner::getComponentParent()
  323. {
  324.     return m_form;
  325. }
  326.  
  327. XFE_ProxyIcon *
  328. XFE_MNBanner::getProxyIcon()
  329. {
  330.   return m_proxyicon;
  331. }
  332.  
  333. char *
  334. XFE_MNBanner::getTitle()
  335. {
  336.   XP_ASSERT(0);
  337.   return 0;
  338. }
  339.  
  340. char *
  341. XFE_MNBanner::getSubtitle()
  342. {
  343.   XP_ASSERT(0);
  344.   return 0;
  345. }
  346.  
  347. char *
  348. XFE_MNBanner::getInfo()
  349. {
  350.     XP_ASSERT(0);
  351.     return 0;
  352. }
  353.  
  354. XFE_Button *
  355. XFE_MNBanner::getMommyButton()
  356. {
  357.     return m_mommyButton;
  358. }
  359.  
  360. XFE_CALLBACK_DEFN(XFE_MNBanner,showFolder)(XFE_NotificationCenter *,
  361.                                  void *, void* cd)
  362. {
  363.   unsigned char arrowDir;
  364.   int32 showFolder = (int32)cd;
  365.  
  366.   XtVaGetValues(m_arrowButton, XmNarrowDirection, &arrowDir, NULL);
  367.  
  368.   if ( (arrowDir == XmARROW_DOWN)  && !showFolder)
  369.     XtVaSetValues(m_arrowButton, XmNarrowDirection, XmARROW_RIGHT, NULL);
  370.   else if ( (arrowDir == XmARROW_RIGHT) && showFolder )
  371.     XtVaSetValues(m_arrowButton, XmNarrowDirection, XmARROW_DOWN, NULL);
  372. }
  373.  
  374.  
  375. void
  376. XFE_MNBanner::setShowFolder(XP_Bool show)
  377. {
  378.   unsigned char arrowDir;
  379.  
  380.   if (!m_arrowButton )
  381.   {
  382.         m_arrowButton =   XtVaCreateManagedWidget("arrowb",
  383.                                      xmArrowButtonWidgetClass,
  384.                                      m_form,
  385.                                      XmNleftAttachment, XmATTACH_FORM,
  386.                                      XmNtopAttachment, XmATTACH_FORM,
  387.                                      XmNbottomAttachment, XmATTACH_FORM,
  388.                                      XmNrightAttachment, XmATTACH_NONE,
  389.                                      XmNarrowDirection, (show? XmARROW_DOWN : XmARROW_RIGHT),
  390.                                      XmNshadowThickness, 0,
  391.                                      NULL);
  392.         XtAddCallback(m_arrowButton, XmNactivateCallback, showFolderBtnCB, this );
  393.  
  394.         getToplevel()->registerInterest(XFE_ThreePaneView::ShowFolder, this,
  395.             (XFE_FunctionNotification)showFolder_cb);
  396.  
  397.   }
  398.   else 
  399.   {
  400.      XtVaGetValues(m_arrowButton, XmNarrowDirection, &arrowDir, NULL);
  401.  
  402.      if ( (arrowDir == XmARROW_DOWN)  && !show)
  403.     XtVaSetValues(m_arrowButton, XmNarrowDirection, XmARROW_RIGHT, NULL);
  404.      else if ( (arrowDir == XmARROW_RIGHT) && show)
  405.     XtVaSetValues(m_arrowButton, XmNarrowDirection, XmARROW_DOWN, NULL);
  406.    }
  407. }
  408.