home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / BookmarkFrame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.9 KB  |  243 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.    BookmarkFrame.cpp -- Bookmark window stuff
  20.    Created: Chris Toshok <toshok@netscape.com>, 7-Aug-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "BookmarkFrame.h"
  26. #include "BookmarkView.h"
  27. #include "xpassert.h"
  28. #include "abdefn.h"                // for kMaxFullNameLength
  29. #include "xpgetstr.h"            // for XP_GetString()
  30. #include "Dashboard.h"
  31.  
  32. #if DEBUG_dora
  33. #define D(x) x
  34. #else
  35. #define D(x)
  36. #endif
  37.  
  38. extern int XFE_BM_FRAME_TITLE;
  39.  
  40. // The singleton bookmark frame
  41. /* static */ XFE_BookmarkFrame * XFE_BookmarkFrame::m_bookmarkFrame = NULL;
  42.  
  43. MenuSpec XFE_BookmarkFrame::file_menu_spec[] = {
  44.   { "newSubmenu",           CASCADEBUTTON,
  45.     (MenuSpec*)&XFE_Frame::new_menu_spec },
  46.     { xfeCmdNewBookmark,  PUSHBUTTON },
  47.     { xfeCmdNewFolder,    PUSHBUTTON },
  48.     { xfeCmdNewSeparator, PUSHBUTTON },
  49.     { xfeCmdOpenBookmarkFile,        PUSHBUTTON },
  50.     { xfeCmdImport,       PUSHBUTTON },
  51.     MENU_SEPARATOR,
  52.     { xfeCmdSaveAs,        PUSHBUTTON },
  53.     MENU_SEPARATOR,
  54.     { xfeCmdOpenSelected, PUSHBUTTON },
  55.     { xfeCmdAddToToolbar,  PUSHBUTTON },
  56.     //{ xfeCmdCreateShortcut, PUSHBUTTON },  // desktop shortcut
  57.     { xfeCmdMakeAlias,  PUSHBUTTON },
  58.     //MENU_SEPARATOR,
  59.     //{ xfeCmdGoOffline, PUSHBUTTON },
  60.     //MENU_SEPARATOR,
  61.     MENU_SEPARATOR,
  62.     { xfeCmdClose,        PUSHBUTTON },  
  63.     { xfeCmdExit,        PUSHBUTTON },
  64.     { NULL }
  65. };
  66.  
  67. MenuSpec XFE_BookmarkFrame::edit_menu_spec[] = {
  68.   { xfeCmdUndo,        PUSHBUTTON },
  69.   { xfeCmdRedo,        PUSHBUTTON },
  70.   MENU_SEPARATOR,
  71.   { xfeCmdCut,        PUSHBUTTON },
  72.   { xfeCmdCopy,        PUSHBUTTON },
  73.   { xfeCmdPaste,    PUSHBUTTON },
  74.   { xfeCmdDelete,    PUSHBUTTON },
  75.   { xfeCmdSelectAll,    PUSHBUTTON },
  76.   MENU_SEPARATOR,
  77.   { xfeCmdFindInObject,    PUSHBUTTON },
  78.   { xfeCmdFindAgain,    PUSHBUTTON },
  79. #ifdef MOZ_MAIL_NEWS
  80.   { xfeCmdSearchAddress,        PUSHBUTTON },
  81. #endif
  82.   MENU_SEPARATOR,
  83.   { xfeCmdBookmarkProperties,    PUSHBUTTON },
  84.   { NULL }
  85. };
  86.  
  87. MenuSpec XFE_BookmarkFrame::view_menu_spec[] = {
  88.   { xfeCmdSortByTitle,           TOGGLEBUTTON, NULL, "sortByRadioGroup", False },
  89.   { xfeCmdSortByLocation,        TOGGLEBUTTON, NULL, "sortByRadioGroup", False },
  90.   { xfeCmdSortByDateLastVisited, TOGGLEBUTTON, NULL, "sortByRadioGroup", False },
  91.   { xfeCmdSortByDateCreated,     TOGGLEBUTTON, NULL, "sortByRadioGroup", False },
  92.   MENU_SEPARATOR,
  93.   { xfeCmdSortAscending,  TOGGLEBUTTON, NULL, "ascendDescendRadioGroup", False },
  94.   { xfeCmdSortDescending, TOGGLEBUTTON, NULL, "ascendDescendRadioGroup", False },
  95.   MENU_SEPARATOR,
  96.   { xfeCmdMoveBookmarkUp,   PUSHBUTTON },
  97.   { xfeCmdMoveBookmarkDown, PUSHBUTTON },
  98.   MENU_SEPARATOR,
  99.   { xfeCmdBookmarksWhatsNew, PUSHBUTTON },
  100.   MENU_SEPARATOR,
  101.   { xfeCmdSetToolbarFolder, PUSHBUTTON },
  102.   { xfeCmdSetNewBookmarkFolder,    PUSHBUTTON },
  103.   { xfeCmdSetBookmarkMenuFolder, PUSHBUTTON },
  104.   { NULL }
  105. };
  106.  
  107. MenuSpec XFE_BookmarkFrame::menu_bar_spec[] = {
  108.   { xfeMenuFile,    CASCADEBUTTON, file_menu_spec },
  109.   { xfeMenuEdit,    CASCADEBUTTON, edit_menu_spec },
  110.   { xfeMenuView,    CASCADEBUTTON, view_menu_spec },
  111.   { xfeMenuWindow,    CASCADEBUTTON, XFE_Frame::window_menu_spec },
  112.   { xfeMenuHelp,     CASCADEBUTTON, XFE_Frame::help_menu_spec },
  113.   { NULL }
  114. };
  115.  
  116. MWContext *XFE_BookmarkFrame::main_bm_context = NULL;
  117.  
  118. XFE_BookmarkFrame::XFE_BookmarkFrame(Widget toplevel,
  119.                                      XFE_Frame *parent_frame,
  120.                                      Chrome *chromespec) 
  121.   : XFE_Frame("bookmarks", toplevel, 
  122.               parent_frame,
  123.               FRAME_BOOKMARK, 
  124.               chromespec,
  125.               False,
  126.               True,
  127.               False,
  128.               True,
  129.               False) // m_destroyOnClose, always keep one Bookmark instance
  130. {
  131.   D(printf("XFE_BookmarkFrame SUB-SYSTEM INSTANCIATING\n");)
  132.  
  133.   XP_ASSERT( m_bookmarkFrame == NULL );
  134.  
  135.   // create the bookmark view
  136.   XFE_BookmarkView *view = new XFE_BookmarkView(this, getViewParent(), 
  137.                                                 NULL, m_context);
  138.   setView(view);
  139.  
  140.   XtVaSetValues(view->getBaseWidget(),
  141.           XmNleftAttachment, XmATTACH_FORM,
  142.         XmNtopAttachment, XmATTACH_FORM,
  143.         XmNrightAttachment, XmATTACH_FORM,
  144.         XmNbottomAttachment, XmATTACH_FORM,
  145.         NULL);
  146.  
  147.   setMenubar(menu_bar_spec);
  148.  
  149.   //
  150.   // Make the bookmark frame title more reasonable
  151.   //
  152.   char title[kMaxFullNameLength+64];
  153.  
  154.   PR_snprintf(title, 
  155.               sizeof(title),
  156.               XP_GetString(XFE_BM_FRAME_TITLE),
  157.               FE_UsersFullName());
  158.  
  159.   setTitle(title);
  160.  
  161.   view->show();
  162.  
  163.   m_dashboard->setShowStatusBar(True);
  164.   m_dashboard->setShowProgressBar(True);
  165.  
  166.   realize();
  167.  
  168.   main_bm_context = m_context;
  169.  
  170.   m_bookmarkFrame = this;
  171. }
  172.  
  173. XFE_BookmarkFrame::~XFE_BookmarkFrame()
  174. {
  175.     D(printf("XFE_BookmarkFrame SUB-SYSTEM DESTRUCTING\n");)
  176.  
  177.     BM_SaveBookmarks(main_bm_context, NULL);
  178.     m_bookmarkFrame = NULL;
  179.     main_bm_context = NULL;
  180. }
  181.  
  182. extern "C" MWContext*
  183. fe_showBookmarks(Widget toplevel, XFE_Frame *parent_frame, Chrome *chromespec)
  184. {
  185.   fe_createBookmarks(toplevel, parent_frame, chromespec);
  186.  
  187.   XFE_BookmarkFrame * bm_frame = XFE_BookmarkFrame::getBookmarkFrame();
  188.  
  189.   XP_ASSERT( bm_frame != NULL );
  190.  
  191.   bm_frame->show();
  192.  
  193.   return bm_frame->getContext();
  194. }
  195.  
  196. extern "C" MWContext* fe_getBookmarkContext()
  197. {
  198.     return XFE_BookmarkFrame::main_bm_context;
  199. }
  200.  
  201. extern "C" void
  202. fe_createBookmarks(Widget toplevel,
  203.                    XFE_Frame *parent_frame,
  204.                    Chrome *chromespec)
  205. {
  206.     XFE_BookmarkFrame::createBookmarkFrame(toplevel,parent_frame,chromespec);
  207. }
  208. //////////////////////////////////////////////////////////////////////////
  209. XP_Bool
  210. XFE_BookmarkFrame::isCommandEnabled(CommandType cmd,
  211.                                    void *calldata, XFE_CommandInfo*)
  212. {
  213.   if (cmd == xfeCmdClose)
  214.     return True;
  215.   else
  216.     return XFE_Frame::isCommandEnabled(cmd, calldata);
  217. }
  218.  
  219. //////////////////////////////////////////////////////////////////////////
  220.  
  221. /* static */ void 
  222. XFE_BookmarkFrame::createBookmarkFrame(Widget        toplevel, 
  223.                                        XFE_Frame *    parent_frame, 
  224.                                        Chrome *        chromespec)
  225. {
  226.     if (m_bookmarkFrame == NULL)
  227.     {
  228.         m_bookmarkFrame = new XFE_BookmarkFrame(toplevel, 
  229.                                                 parent_frame, 
  230.                                                 chromespec);
  231.     }
  232. }
  233. //////////////////////////////////////////////////////////////////////////
  234. /* static */ XFE_BookmarkFrame * 
  235. XFE_BookmarkFrame::getBookmarkFrame()
  236. {
  237.     XP_ASSERT( m_bookmarkFrame != NULL );
  238.  
  239.     return m_bookmarkFrame;
  240. }
  241. //////////////////////////////////////////////////////////////////////////
  242.  
  243.