From ed205c61fe2a09930f75bfcb32af7bd59e7f31f0 Mon Sep 17 00:00:00 2001 From: "ramiro%netscape.com" Date: Tue, 13 Oct 1998 07:22:09 +0000 Subject: [PATCH] Improve the toolbar item configure and initialize interfaces --- cmd/xfe/src/ToolbarButton.cpp | 366 ++++++++++++++++++++++++++++++++-- cmd/xfe/src/ToolbarButton.h | 27 +++ cmd/xfe/src/ToolbarCascade.h | 3 +- cmd/xfe/src/ToolbarItem.cpp | 8 +- cmd/xfe/src/ToolbarItem.h | 17 ++ cmd/xfe/src/ToolbarUrlBar.cpp | 42 ++-- cmd/xfe/src/ToolbarUrlBar.h | 7 + 7 files changed, 431 insertions(+), 39 deletions(-) diff --git a/cmd/xfe/src/ToolbarButton.cpp b/cmd/xfe/src/ToolbarButton.cpp index afeb03b982ba..790c02ff7561 100644 --- a/cmd/xfe/src/ToolbarButton.cpp +++ b/cmd/xfe/src/ToolbarButton.cpp @@ -28,9 +28,15 @@ ////////////////////////////////////////////////////////////////////////// #include "ToolbarButton.h" +#include "RDFUtils.h" +#include "BrowserFrame.h" // for fe_reuseBrowser() #include +#include "prefapi.h" + +extern "C" RDF_NCVocab gNavCenter; + ////////////////////////////////////////////////////////////////////////// // // XFE_ToolbarButton notifications @@ -66,11 +72,9 @@ XFE_ToolbarButton::~XFE_ToolbarButton() /* virtual */ void XFE_ToolbarButton::initialize() { - Widget bw = createBaseWidget(getParent(),getName()); + Widget button = createBaseWidget(getParent(),getName()); - setBaseWidget(bw); - - installDestroyHandler(); + setBaseWidget(button); } ////////////////////////////////////////////////////////////////////////// @@ -154,6 +158,61 @@ XFE_ToolbarButton::createBaseWidget(Widget parent, } ////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +// +// Configure +// +////////////////////////////////////////////////////////////////////////// +/* virtual */ void +XFE_ToolbarButton::configure() +{ + XP_ASSERT( isAlive() ); + + // TODO, all the toolbar item resizing magic + // XtVaSetValues(m_widget,XmNforceDimensionToMax,False,NULL); + + // Set the item's label + XFE_RDFUtils::setItemLabelString(getAncestorContext(), + m_widget, + getHtResource()); + + // Set the item's style and layout + int32 button_style = getButtonStyle(); + unsigned char button_layout = styleToLayout(button_style); + + if (button_style == BROWSER_TOOLBAR_TEXT_ONLY) + { + XtVaSetValues(m_widget, + XmNpixmap, XmUNSPECIFIED_PIXMAP, + XmNpixmapMask, XmUNSPECIFIED_PIXMAP, + NULL); + + XtVaSetValues(m_widget, XmNbuttonLayout, button_layout, NULL); + } + else + { + Pixmap pixmap; + Pixmap pixmapMask; + + getPixmapsForEntry(&pixmap,&pixmapMask,NULL,NULL); + + XtVaSetValues(m_widget, + XmNpixmap, pixmap, + XmNpixmapMask, pixmapMask, + XmNbuttonLayout, button_layout, + NULL); + } + +#ifdef NOT_YET + // Add popup callback to button + XtAddCallback(m_widget, + XmNbutton3DownCallback, + &XFE_RDFToolbar::popupCB, + (XtPointer) this); +#endif +} +////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// // // Tool tip support @@ -194,32 +253,297 @@ XFE_ToolbarButton::docStringClear(XmString /* string */) } ////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +// +// Style and layout interface +// +////////////////////////////////////////////////////////////////////////// +int32 +XFE_ToolbarButton::getButtonStyle() +{ + int32 button_style = BROWSER_TOOLBAR_TEXT_ONLY; + void * data = NULL; + HT_Resource entry = getHtResource(); + + XP_ASSERT( entry != NULL ) ; + + // Get the Toolbar displaymode from HT + HT_GetTemplateData(HT_TopNode(HT_GetView(entry)), + gNavCenter->toolbarDisplayMode, + HT_COLUMN_STRING, + &data); + + // No value provided initially. So get it from prefs and set in HT + if (!data) + { + /* int result = */ PREF_GetIntPref("browser.chrome.toolbar_style", + &button_style); + + if (button_style == BROWSER_TOOLBAR_TEXT_ONLY) + { + HT_SetNodeData(HT_TopNode(HT_GetView(entry)), + gNavCenter->toolbarDisplayMode, + HT_COLUMN_STRING, + "text"); + } + else if (button_style == BROWSER_TOOLBAR_ICONS_ONLY) + { + HT_SetNodeData(HT_TopNode(HT_GetView(entry)), + gNavCenter->toolbarDisplayMode, + HT_COLUMN_STRING, + "pictures"); + } + else + { + HT_SetNodeData(HT_TopNode(HT_GetView(entry)), + gNavCenter->toolbarDisplayMode, + HT_COLUMN_STRING, + "PicturesAndText"); + } + } + // Value is found in HT + else + { + char * answer = (char *) data; + + if ((!XP_STRCASECMP(answer, "text"))) + { + button_style = BROWSER_TOOLBAR_TEXT_ONLY; + } + else if ((!XP_STRCASECMP(answer, "icons"))) + { + button_style = BROWSER_TOOLBAR_ICONS_ONLY; + } + else + { + button_style = BROWSER_TOOLBAR_ICONS_AND_TEXT; + } + } + + return button_style; +} +////////////////////////////////////////////////////////////////////////// +unsigned char +XFE_ToolbarButton::styleToLayout(int32 button_style) +{ + unsigned char button_layout = XmBUTTON_LABEL_ONLY; + void * data = NULL; + HT_Resource entry = getHtResource(); + + XP_ASSERT( entry != NULL ) ; + + if (button_style == BROWSER_TOOLBAR_ICONS_AND_TEXT) + { + // Get the Toolbar bitmap position from HT */ + HT_GetTemplateData(HT_TopNode(HT_GetView(entry)), + gNavCenter->toolbarBitmapPosition, + HT_COLUMN_STRING, + &data); + + if (data) + { + char * answer = (char *) data; + + if ((!XP_STRCASECMP(answer, "top"))) + { + button_layout = XmBUTTON_LABEL_ON_BOTTOM; + } + else if ((!XP_STRCASECMP(answer, "side"))) + { + button_layout = XmBUTTON_LABEL_ON_RIGHT; + } + } + // Value not provided. It is top for command buttons and side + // for personal + else + { + if (XFE_RDFUtils::ht_IsFECommand(entry)) + { + button_layout = XmBUTTON_LABEL_ON_BOTTOM; + } + else + { + button_layout = XmBUTTON_LABEL_ON_RIGHT; + } + } + } + else if (button_style == BROWSER_TOOLBAR_ICONS_ONLY) + { + button_layout = XmBUTTON_PIXMAP_ONLY; + } + else if (button_style == BROWSER_TOOLBAR_TEXT_ONLY) + { + button_layout = XmBUTTON_LABEL_ONLY; + } + + return button_layout; +} +////////////////////////////////////////////////////////////////////////// +void +XFE_ToolbarButton::getPixmapsForEntry(Pixmap * pixmapOut, + Pixmap * maskOut, + Pixmap * armedPixmapOut, + Pixmap * armedMaskOut) +{ + IconGroup * ig = NULL; + HT_Resource entry = getHtResource(); + + // Right now the only way an entry can be NULL is for the + // bookmarkMoreButton which kinda looks and acts like a folder so + // we use folder pixmaps for it + if (!entry) + { + ig = &BM_Folder_group; + } + else + { +#ifdef NOT_YET + if (hasCustomIcon(entry)) {} /*else {*/ +#endif /*NOT_YET*/ + if (XFE_RDFUtils::ht_IsFECommand(entry)) + { + const char* url = HT_GetNodeURL(entry); + + ig = IconGroup_findGroupForName(url + 8); + } + else + { + if (HT_IsContainer(entry)) + { + XP_Bool is_menu = False;//(entry == getMenuFolder()); + XP_Bool is_add = False;//(entry == getAddFolder()); + + + if (is_add && is_menu) ig = &BM_NewAndMenuFolder_group; + else if (is_add) ig = &BM_NewFolder_group; + else if (is_menu) ig = &BM_MenuFolder_group; + else ig = &BM_Folder_group; + } + else + { + int url_type = NET_URL_Type(HT_GetNodeURL(entry)); + + if (url_type == IMAP_TYPE_URL || url_type == MAILBOX_TYPE_URL) + ig = &BM_MailBookmark_group; + else if (url_type == NEWS_TYPE_URL) + ig = &BM_NewsBookmark_group; + else + ig = &BM_Bookmark_group; + } + } + } + + Pixmap pixmap = XmUNSPECIFIED_PIXMAP; + Pixmap mask = XmUNSPECIFIED_PIXMAP; + Pixmap armedPixmap = XmUNSPECIFIED_PIXMAP; + Pixmap armedMask = XmUNSPECIFIED_PIXMAP; + + if (ig) + { + Widget ancestor_shell = getAncestorFrame()->getBaseWidget(); + + IconGroup_createAllIcons(ig, + ancestor_shell, + XfeForeground(ancestor_shell), + XfeBackground(ancestor_shell)); + + pixmap = ig->pixmap_icon.pixmap; + mask = ig->pixmap_icon.mask; + armedPixmap = ig->pixmap_mo_icon.pixmap; + armedMask = ig->pixmap_mo_icon.mask; + } + + if (pixmapOut) + { + *pixmapOut = pixmap; + } + + if (maskOut) + { + *maskOut = mask; + } + + if (armedPixmapOut) + { + *armedPixmapOut = armedPixmap; + } + + if (armedMaskOut) + { + *armedMaskOut = armedMask; + } + +} + +////////////////////////////////////////////////////////////////////////// +// +// Button callback interface +// +////////////////////////////////////////////////////////////////////////// +/* virtual */ void +XFE_ToolbarButton::activate() +{ + HT_Resource entry = getHtResource(); + + XP_ASSERT( entry != NULL ); + + // Check for xfe commands + if (XFE_RDFUtils::ht_IsFECommand(entry)) + { + // Convert the entry name to a xfe command + CommandType cmd = XFE_RDFUtils::ht_GetFECommand(entry); + + XP_ASSERT( cmd != NULL ); + + // Fill in the command info + XFE_CommandInfo info(XFE_COMMAND_EVENT_ACTION, + m_widget, + NULL /*event*/, + NULL /*params*/, + 0 /*num_params*/); + + XFE_Frame * frame = getAncestorFrame(); + + XP_ASSERT( frame != NULL ); + + // If the frame handles the command and its enabled, execute it. + if (frame->handlesCommand(cmd,NULL,&info) && + frame->isCommandEnabled(cmd,NULL,&info)) + { + xfe_ExecuteCommand(frame,cmd,NULL,&info); + + //_frame->notifyInterested(Command::commandDispatchedCallback, + //callData); + } + } + // Other URLs + else if (!HT_IsContainer(entry)) + { + char * address = HT_GetNodeURL(entry); + URL_Struct * url = NET_CreateURLStruct(address,NET_DONT_RELOAD); + MWContext * context = getAncestorContext(); + + XP_ASSERT( context != NULL ); + + fe_reuseBrowser(context,url); + } +} +////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// // // Private callbacks // ////////////////////////////////////////////////////////////////////////// /* static */ void -XFE_ToolbarButton::activateCB(Widget w, +XFE_ToolbarButton::activateCB(Widget /* w */, XtPointer clientData, - XtPointer callData) + XtPointer /* callData */) { - XFE_ToolbarButton * button = (XFE_ToolbarButton*) clientData; - XfeButtonCallbackStruct * cd = (XfeButtonCallbackStruct *) callData; - CommandType cmd = button->getCommand(); - void * cmdCallData = button->getCallData(); + XFE_ToolbarButton * button = (XFE_ToolbarButton *) clientData; - // The command info - only widget and event available - XFE_CommandInfo info(XFE_COMMAND_BUTTON_ACTIVATE, - w, - cd->event); - // Command arguments - XFE_DoCommandArgs cmdArgs(cmd, - cmdCallData, - &info); + XP_ASSERT( button != NULL ); - // Send a message that will perform an action. - button->notifyInterested(XFE_ToolbarButton::doCommandNotice, - (void *) & cmdArgs); + button->activate(); } ////////////////////////////////////////////////////////////////////////// diff --git a/cmd/xfe/src/ToolbarButton.h b/cmd/xfe/src/ToolbarButton.h index 0abaa185ea2b..3b47b4138561 100644 --- a/cmd/xfe/src/ToolbarButton.h +++ b/cmd/xfe/src/ToolbarButton.h @@ -86,6 +86,13 @@ protected: virtual Widget createBaseWidget (Widget parent, const String name); + ////////////////////////////////////////////////////////////////////// + // // + // Configure // + // // + ////////////////////////////////////////////////////////////////////// + virtual void configure (); + ////////////////////////////////////////////////////////////////////// // // // ToolTip interface // @@ -101,6 +108,26 @@ protected: virtual void docStringClear (XmString string); + ////////////////////////////////////////////////////////////////////// + // // + // Style and layout interface // + // // + ////////////////////////////////////////////////////////////////////// + int32 getButtonStyle (); + unsigned char styleToLayout (int32 button_style); + + void getPixmapsForEntry (Pixmap * pixmapOut, + Pixmap * maskOut, + Pixmap * armedPixmapOut, + Pixmap * armedMaskOut); + + ////////////////////////////////////////////////////////////////////// + // // + // Button callback interface // + // // + ////////////////////////////////////////////////////////////////////// + virtual void activate (); + private: ////////////////////////////////////////////////////////////////////// diff --git a/cmd/xfe/src/ToolbarCascade.h b/cmd/xfe/src/ToolbarCascade.h index 605fbb1b3294..45f56eced9c0 100644 --- a/cmd/xfe/src/ToolbarCascade.h +++ b/cmd/xfe/src/ToolbarCascade.h @@ -36,8 +36,9 @@ class XFE_ToolbarCascade : public XFE_ToolbarButton { public: - XFE_ToolbarCascade(XFE_Frame * frame, + XFE_ToolbarCascade(XFE_Frame * frame, Widget parent, + HT_Resource htResource, const String name); virtual ~XFE_ToolbarCascade(); diff --git a/cmd/xfe/src/ToolbarItem.cpp b/cmd/xfe/src/ToolbarItem.cpp index baace7ba295d..1ad5b5578f16 100644 --- a/cmd/xfe/src/ToolbarItem.cpp +++ b/cmd/xfe/src/ToolbarItem.cpp @@ -97,7 +97,7 @@ XFE_ToolbarItem::getHtResource() /* virtual */ void XFE_ToolbarItem::setBaseWidget(Widget w) { - printf("XFE_ToolbarItem::setBaseWidget(%s)\n",XtName(w)); +// printf("XFE_ToolbarItem::setBaseWidget(%s)\n",XtName(w)); XP_ASSERT( XfeIsAlive(w) ); @@ -113,6 +113,12 @@ XFE_ToolbarItem::setBaseWidget(Widget w) // Add tooltip support addToolTipSupport(); + + // Configure the item + configure(); + + // Install destroy handler (magic garbage collection for the item) + installDestroyHandler(); } ////////////////////////////////////////////////////////////////////////// diff --git a/cmd/xfe/src/ToolbarItem.h b/cmd/xfe/src/ToolbarItem.h index d05ad5c25656..1a39a9b9b156 100644 --- a/cmd/xfe/src/ToolbarItem.h +++ b/cmd/xfe/src/ToolbarItem.h @@ -61,6 +61,12 @@ public: // // // Initialize // // // + // This method should be called by the item creator to initialize // + // the item. This is needed for abstract methods to be properly // + // called. The alternative is to call initialize directlry from // + // the XFE_ToolbarItem ctor - but it does not work because abstract // + // methods might not have been properly set up by then. // + // // ////////////////////////////////////////////////////////////////////// virtual void initialize () = 0; @@ -81,6 +87,17 @@ protected: virtual Widget createBaseWidget (Widget parent, const String name) = 0; + ////////////////////////////////////////////////////////////////////// + // // + // Configure // + // // + // This method is called as soon as the base widget has been set // + // so that sub classes can configure the item according to their // + // needs. // + // // + ////////////////////////////////////////////////////////////////////// + virtual void configure () = 0; + ////////////////////////////////////////////////////////////////////// // // // ToolTip interface // diff --git a/cmd/xfe/src/ToolbarUrlBar.cpp b/cmd/xfe/src/ToolbarUrlBar.cpp index b388df69d651..3ab003c08b2b 100644 --- a/cmd/xfe/src/ToolbarUrlBar.cpp +++ b/cmd/xfe/src/ToolbarUrlBar.cpp @@ -66,11 +66,21 @@ XFE_ToolbarUrlBar::~XFE_ToolbarUrlBar() /* virtual */ void XFE_ToolbarUrlBar::initialize() { - Widget uw = createBaseWidget(getParent(),getName()); + Widget urlbar = createBaseWidget(getParent(),getName()); - setBaseWidget(uw); + setBaseWidget(urlbar); +} +////////////////////////////////////////////////////////////////////////// - installDestroyHandler(); +////////////////////////////////////////////////////////////////////////// +// +// Configure +// +////////////////////////////////////////////////////////////////////////// +/* virtual */ void +XFE_ToolbarUrlBar::configure() +{ + XP_ASSERT( isAlive() ); createProxyIcon(m_widget,"proxyIcon"); } @@ -112,25 +122,25 @@ XFE_ToolbarUrlBar::createBaseWidget(Widget parent, XP_ASSERT( XfeIsAlive(parent) ); XP_ASSERT( name != NULL ); - Widget url_bar; + Widget urlbar; - url_bar = XtVaCreateWidget(name, - xfeFancyBoxWidgetClass, - parent, - XmNforceDimensionToMax, False, - XmNcomboBoxType, XmCOMBO_BOX_EDITABLE, - XmNwidth, 400, - XmNusePreferredWidth, False, + urlbar = XtVaCreateWidget(name, + xfeFancyBoxWidgetClass, + parent, + XmNforceDimensionToMax, False, + XmNcomboBoxType, XmCOMBO_BOX_EDITABLE, + XmNwidth, 400, + XmNusePreferredWidth, False, // XmNtraversalOn, False, // XmNhighlightThickness, 0, - NULL); + NULL); - XtAddCallback(url_bar, + XtAddCallback(urlbar, XmNtextActivateCallback, XFE_ToolbarUrlBar::textActivateCB, (XtPointer) this); - return url_bar; + return urlbar; } ////////////////////////////////////////////////////////////////////////// @@ -235,9 +245,9 @@ XFE_ToolbarUrlBar::createProxyIcon(Widget parent, // ////////////////////////////////////////////////////////////////////////// /* static */ void -XFE_ToolbarUrlBar::textActivateCB(Widget w, +XFE_ToolbarUrlBar::textActivateCB(Widget /* w */, XtPointer clientData, - XtPointer callData) + XtPointer /* callData */) { XFE_ToolbarUrlBar * urlbar = (XFE_ToolbarUrlBar*) clientData; diff --git a/cmd/xfe/src/ToolbarUrlBar.h b/cmd/xfe/src/ToolbarUrlBar.h index cfd2e23f1359..732e564b2199 100644 --- a/cmd/xfe/src/ToolbarUrlBar.h +++ b/cmd/xfe/src/ToolbarUrlBar.h @@ -77,6 +77,13 @@ protected: virtual Widget createBaseWidget (Widget parent, const String name); + ////////////////////////////////////////////////////////////////////// + // // + // Configure // + // // + ////////////////////////////////////////////////////////////////////// + virtual void configure (); + ////////////////////////////////////////////////////////////////////// // // // ToolTip interface //