Move the tree widgetry from XFE_RDFView to XFE_RDFTreeView.

This commit is contained in:
ramiro%netscape.com 1998-08-11 11:51:25 +00:00
Родитель 60175de152
Коммит 76567fee8a
7 изменённых файлов: 1332 добавлений и 1036 удалений

Просмотреть файл

@ -113,6 +113,8 @@ XFE_BrowserView::showNavCenter()
// Add _navCenterView to the sub-view list of browser view
addView(_navCenterView);
_navCenterView->show();
}
// Show the nav center

Просмотреть файл

@ -124,6 +124,7 @@ CPPSRCS = \
PrefsLang.cpp \
PrefsProxiesView.cpp \
RDFView.cpp \
RDFTreeView.cpp \
RadioGroup.cpp \
Splash.cpp \
Toolbar.cpp \

Просмотреть файл

@ -88,15 +88,17 @@ XFE_NavCenterView::XFE_NavCenterView(XFE_Component *toplevel_component,
// Set the view type.
m_viewType = VIEW_NAVCENTER;
Widget nav_form = XtVaCreateManagedWidget("nav_form",
xmFormWidgetClass,
parent,
NULL);
setBaseWidget(nav_form);
Widget navCenterMainForm =
XtVaCreateManagedWidget("navCenterMainForm",
xmFormWidgetClass,
parent,
NULL);
setBaseWidget(navCenterMainForm);
m_selector = XtVaCreateManagedWidget("selector",
xfeToolScrollWidgetClass,
nav_form,
navCenterMainForm,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
@ -115,32 +117,41 @@ XFE_NavCenterView::XFE_NavCenterView(XFE_Component *toplevel_component,
XmNshadowThickness, 0,
NULL);
rdf_parent = XtVaCreateManagedWidget("rdf_form",
xmFormWidgetClass,
nav_form,
XmNtopAttachment, XmATTACH_FORM,
m_htview = NULL;
m_pane = NULL;
m_rdfview = new XFE_RDFView(this, m_widget, this, context);
XtVaSetValues(m_rdfview->getBaseWidget(),
XmNtopAttachment, XmATTACH_FORM,
#ifdef HTML_PANE
XmNbottomAttachment, XmATTACH_NONE,
XmNbottomAttachment, XmATTACH_NONE,
#else
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
#endif
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, m_selector,
XmNrightAttachment, XmATTACH_FORM,
XmNtopOffset, 0,
XmNbottomOffset, 1,
XmNleftOffset, 0,
XmNrightOffset, 0,
XmNshadowThickness, 2,
XmNshadowType, XmSHADOW_IN,
NULL);
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, m_selector,
XmNrightAttachment, XmATTACH_FORM,
// Put this stuff in the resource file
// XmNtopOffset, 0,
// XmNbottomOffset, 1,
// XmNleftOffset, 0,
// XmNrightOffset, 0,
// XmNshadowThickness, 2,
// XmNshadowType, XmSHADOW_IN,
NULL);
m_rdfview->setStandAloneState(m_isStandalone);
#ifdef HTML_PANE
m_htmlview = new XFE_HTMLView(this, nav_form, NULL, context);
m_htmlview = new XFE_HTMLView(this, navCenterMainForm, NULL, context);
Widget html_base = m_htmlview->getBaseWidget();
XtVaSetValues(html_base,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, rdf_parent,
XmNtopWidget, m_rdfview->getBaseWidget(),
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, m_selector,
@ -148,12 +159,7 @@ XFE_NavCenterView::XFE_NavCenterView(XFE_Component *toplevel_component,
NULL);
#endif
m_htview = NULL;
m_pane = NULL;
m_rdfview = new XFE_RDFView(this, rdf_parent, this, context);
m_rdfview->setStandAloneState(m_isStandalone);
HT_Notification ns = new HT_NotificationStruct;
ns->notifyProc = &XFE_NavCenterView::notify_cb;
@ -176,7 +182,6 @@ XFE_NavCenterView::XFE_NavCenterView(XFE_Component *toplevel_component,
m_htmlview->getURL(NET_CreateURLStruct("http://dunk/",NET_DONT_RELOAD));
#endif
XtManageChild(nav_form);
}
@ -403,7 +408,9 @@ XFE_NavCenterView::handleDisplayPixmap(Widget w, IL_Pixmap * image, IL_Pixmap *
{
XFE_RDFImage * rdfImage;
#ifdef DEBUG_radha
printf("In NavCenterView:handleDisplayPixmap\n");
#endif
// Get handle to the RDFImage object from the cache
for (int i = 0; i < m_numRDFImagesLoaded; i ++)
@ -423,7 +430,9 @@ XFE_NavCenterView::handleNewPixmap(Widget w, IL_Pixmap * image, Boolean mask)
{
XFE_RDFImage * rdfImage;
#ifdef DEBUG_radha
printf("In NavCenterView:handlenewPixmap\n");
#endif
// Get handle to the RDFImage object from the cache
for (int i = 0; i < m_numRDFImagesLoaded; i ++)
@ -444,7 +453,10 @@ XFE_NavCenterView::handleImageComplete(Widget w, IL_Pixmap * image)
XFE_RDFImage * rdfImage;
#ifdef DEBUG_radha
printf("In NavCenterView:handleImageComplete\n");
#endif
// Get handle to the RDFImage object from the cache
for (int i = 0; i < m_numRDFImagesLoaded; i ++)
@ -465,16 +477,18 @@ void ImageCompleteCallback(XtPointer client_data)
Widget button = (Widget )cb->widget;
Dimension b_width=0, b_height=0;
#ifdef DEBUG_radha
printf("Inside ImageCompleteCallback\n");
#endif
XtUnmanageChild(button);
XtVaGetValues(button, XmNwidth, &b_width, XmNheight, &b_height, NULL);
XtVaSetValues(button, XmNheight,(cb->height + b_height),
XmNpixmap, cb->image,
XmNpixmapMask, cb->mask,
XmNbuttonLayout, XmBUTTON_LABEL_ON_BOTTOM,
XmNlabelAlignment, XmALIGNMENT_CENTER,
XmNpixmap, cb->image,
XmNpixmapMask, cb->mask,
XmNbuttonLayout, XmBUTTON_PIXMAP_ONLY,
XmNlabelAlignment, XmALIGNMENT_CENTER,
NULL);
XtManageChild(button);
XP_FREE(cb);

975
cmd/xfe/src/RDFTreeView.cpp Normal file
Просмотреть файл

@ -0,0 +1,975 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*----------------------------------------------------------------------*/
/* */
/* Name: RDFTreeView.cpp */
/* Description: XFE_RDFTreeView component header file - A class to */
/* encapsulate and rdf tree widget. */
/* Author: Ramiro Estrugo <ramiro@netscape.com> */
/* */
/*----------------------------------------------------------------------*/
#include "RDFTreeView.h"
#include "Command.h"
#include "xfe2_extern.h"
#include "xpgetstr.h"
#include <XmL/Tree.h>
#include <Xfe/Xfe.h>
#define TREE_NAME "RdfTree"
#ifdef DEBUG_slamm
#define D(x) x
#else
#define D(x)
#endif
// pixmaps for use in the bookmark window.
fe_icon XFE_RDFTreeView::bookmark = { 0 };
fe_icon XFE_RDFTreeView::closedFolder = { 0 };
fe_icon XFE_RDFTreeView::openedFolder = { 0 };
#define SECONDS_PER_DAY 86400L
extern int XP_BKMKS_HOURS_AGO;
extern int XP_BKMKS_DAYS_AGO;
extern int XP_BKMKS_LESS_THAN_ONE_HOUR_AGO;
struct RDFColumnData
{
RDFColumnData(void) : token(NULL), token_type(0) {}
RDFColumnData(void *t, uint32 tt) : token(t), token_type(tt) {}
void* token;
uint32 token_type;
};
void HTFE_MakePrettyDate(char* buffer, time_t lastVisited)
{
buffer[0] = 0;
time_t today = XP_TIME();
int elapsed = today - lastVisited;
if (elapsed < SECONDS_PER_DAY)
{
int32 hours = (elapsed + 1800L) / 3600L;
if (hours < 1)
{
XP_STRCPY(buffer, XP_GetString(XP_BKMKS_LESS_THAN_ONE_HOUR_AGO));
}
sprintf(buffer, XP_GetString(XP_BKMKS_HOURS_AGO), hours);
}
else if (elapsed < (SECONDS_PER_DAY * 31))
{
sprintf(buffer, XP_GetString(XP_BKMKS_DAYS_AGO),
(elapsed + (SECONDS_PER_DAY / 2)) / SECONDS_PER_DAY);
}
else
{
struct tm* tmp;
tmp = localtime(&lastVisited);
sprintf(buffer, asctime(tmp));
}
}
//
// Command Handling
//
//
// This acts as an encapsulator for the doCommand() method.
// Sub-classes impliment a reallyDoCommand(), and leave the
// boring maintainence work to this class. This approach
// saves every sub-class from calling super::doCommand(),
// which would really be a drag, now wouldn't it.
//
class XFE_RDFTreeViewCommand : public XFE_ViewCommand
{
public:
XFE_RDFTreeViewCommand(char* name) : XFE_ViewCommand(name) {};
virtual void reallyDoCommand(XFE_RDFTreeView*, XFE_CommandInfo*) = 0;
virtual XP_Bool requiresChromeUpdate() {
return TRUE;
};
void doCommand(XFE_View* v_view, XFE_CommandInfo* info) {
XFE_RDFTreeView* view = (XFE_RDFTreeView*)v_view;
reallyDoCommand(view, info);
if (requiresChromeUpdate()) {
//XXX view->updateChrome();
}
};
};
class XFE_RDFTreeViewAlwaysEnabledCommand : public XFE_RDFTreeViewCommand
{
public:
XFE_RDFTreeViewAlwaysEnabledCommand(char* name) : XFE_RDFTreeViewCommand(name) {};
XP_Bool isEnabled(XFE_View*, XFE_CommandInfo*) {
return True;
};
};
class RdfPopupCommand : public XFE_RDFTreeViewAlwaysEnabledCommand
{
public:
RdfPopupCommand() : XFE_RDFTreeViewAlwaysEnabledCommand(xfeCmdShowPopup) {};
virtual XP_Bool isSlow() {
return FALSE;
};
void reallyDoCommand(XFE_RDFTreeView* view, XFE_CommandInfo* info) {
view->doPopup(info->event);
};
};
// END OF COMMAND DEFINES
static XFE_CommandList* my_commands = 0;
XFE_RDFTreeView::XFE_RDFTreeView(XFE_Component * toplevel,
Widget parent,
XFE_View * parent_view,
MWContext * context) :
XFE_View(toplevel, parent_view, context),
_ht_rdfView(NULL),
_popup(NULL),
_standAloneState(False)
{
if (!my_commands)
{
registerCommand(my_commands, new RdfPopupCommand);
}
// Create the tree widget
Widget tree =
XtVaCreateWidget(TREE_NAME,
xmlTreeWidgetClass,
parent,
XmNshadowThickness, 0,
XmNhorizontalSizePolicy, XmRESIZE_IF_POSSIBLE,
XmNallowColumnResize, True,
XmNselectionPolicy, XmSELECT_MULTIPLE_ROW,
XmNheadingRows, 1,
XmNvisibleRows, 14,
XmNhideUnhideButtons, True,
NULL);
setBaseWidget(tree);
XtVaSetValues(m_widget, XmNcellAlignment, XmALIGNMENT_LEFT, NULL);
XtVaSetValues(m_widget,
XmNcellDefaults, True,
XmNcellAlignment, XmALIGNMENT_LEFT,
NULL);
init_pixmaps();
XtAddCallback(m_widget, XmNexpandCallback, expand_row_cb, this);
XtAddCallback(m_widget, XmNcollapseCallback, collapse_row_cb, this);
XtAddCallback(m_widget, XmNdeleteCallback, delete_cb, NULL);
XtAddCallback(m_widget, XmNactivateCallback, activate_cb, this);
XtAddCallback(m_widget, XmNresizeCallback, resize_cb, this);
XtAddCallback(m_widget, XmNeditCallback, edit_cell_cb, this);
XtAddCallback(m_widget, XmNselectCallback, select_cb, this);
XtAddCallback(m_widget, XmNdeselectCallback, deselect_cb, this);
XtAddCallback(m_widget, XmNpopupCallback, popup_cb, this);
//fe_AddTipStringCallback(outline, XFE_Outliner::tip_cb, this);
}
//////////////////////////////////////////////////////////////////////////
XFE_RDFTreeView::~XFE_RDFTreeView()
{
if (_popup)
{
delete _popup;
}
}
//////////////////////////////////////////////////////////////////////////
void
XFE_RDFTreeView::init_pixmaps(void)
{
Pixel bg_pixel;
XtVaGetValues(m_widget, XmNbackground, &bg_pixel, 0);
Widget shell = XfeAncestorFindByClass(getToplevel()->getBaseWidget(),
shellWidgetClass,
XfeFIND_ANY);
if (!bookmark.pixmap)
fe_NewMakeIcon(shell,
BlackPixelOfScreen(XtScreen(m_widget)),
bg_pixel,
&bookmark,
NULL,
BM_Bookmark.width, BM_Bookmark.height,
BM_Bookmark.mono_bits, BM_Bookmark.color_bits,
BM_Bookmark.mask_bits, FALSE);
if (!closedFolder.pixmap)
fe_NewMakeIcon(shell,
BlackPixelOfScreen(XtScreen(m_widget)),
bg_pixel,
&closedFolder,
NULL,
BM_Folder.width, BM_Folder.height,
BM_Folder.mono_bits, BM_Folder.color_bits,
BM_Folder.mask_bits, FALSE);
if (!openedFolder.pixmap)
fe_NewMakeIcon(shell,
BlackPixelOfScreen(XtScreen(m_widget)),
bg_pixel,
&openedFolder,
NULL,
BM_FolderO.width, BM_FolderO.height,
BM_FolderO.mono_bits, BM_FolderO.color_bits,
BM_FolderO.mask_bits, FALSE);
}
//////////////////////////////////////////////////////////////////////////
void
XFE_RDFTreeView::activate_row(int row)
{
HT_Resource node = HT_GetNthItem(_ht_rdfView, row);
if (!node) return;
#if 0
if (data->ctrl)
{
HT_ToggleSelection(node);
m_outliner->toggleSelected(data->row);
}
else if (data->shift)
{
HT_SetSelectionRange(node, m_node);
m_outliner->trimOrExpandSelection(data->row);
}
else
{
HT_SetSelection(node);
m_outliner->selectItemExclusive(data->row);
}
getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
#endif /*0*/
if (!HT_IsContainer(node)) {
// Dispatch in new window
char *s = HT_GetNodeURL (node);
URL_Struct *url = NET_CreateURLStruct (s, NET_DONT_RELOAD);
//url->window_target = XP_STRDUP("_rdf_target");
fe_reuseBrowser (m_contextData, url);
}
}
//////////////////////////////////////////////////////////////////////////
void
XFE_RDFTreeView::resize_cb(Widget,
XtPointer clientData,
XtPointer callData)
{
XFE_RDFTreeView *obj = (XFE_RDFTreeView*)clientData;
obj->resize(callData);
}
void
XFE_RDFTreeView::resize(XtPointer callData)
{
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct*)callData;
XP_ASSERT(m_widget);
if(!m_widget)
return;
if (cbs->reason == XmCR_RESIZE_COLUMN)
{
D( printf("Inside XFE_RDFTreeView::resize(COLUMN, %d)\n", cbs->column););
}
}
void
XFE_RDFTreeView::refresh(HT_Resource node)
{
if (!_ht_rdfView) return;
XP_ASSERT(HT_IsContainer(node));
if (!HT_IsContainer(node)) return;
if (HT_IsContainerOpen(node))
{
HT_Resource child;
HT_Cursor child_cursor = HT_NewCursor(node);
while (child = HT_GetNextItem(child_cursor))
{
add_row(child);
if (HT_IsContainer(child) && HT_IsContainerOpen(child))
refresh(child);
}
HT_DeleteCursor(child_cursor);
}
else
{
int row = HT_GetNodeIndex(_ht_rdfView, node);
XmLTreeDeleteChildren(m_widget, row);
}
}
void
XFE_RDFTreeView::edit_cell_cb(Widget,
XtPointer clientData,
XtPointer callData)
{
XFE_RDFTreeView *obj = (XFE_RDFTreeView*)clientData;
obj->edit_cell(callData);
}
void
XFE_RDFTreeView::edit_cell(XtPointer callData)
{
XP_ASSERT(m_widget);
if(!m_widget)
return;
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct*)callData;
HT_Resource node = HT_GetNthItem (_ht_rdfView, cbs->row);
if (node && cbs->reason == XmCR_EDIT_COMPLETE)
{
XmLGridColumn column = XmLGridGetColumn(m_widget, XmCONTENT,
cbs->column);
RDFColumnData *column_data = NULL;
XtVaGetValues(m_widget,
XmNcolumnPtr, column,
XmNcolumnUserData, &column_data,
NULL);
XmLGridRow row = XmLGridGetRow(m_widget, XmCONTENT, cbs->row);
XmString cell_string;
XtVaGetValues(m_widget,
XmNcolumnPtr, column,
XmNrowPtr, row,
XmNcellString, &cell_string,
NULL);
char *text;
XmStringGetLtoR(cell_string, XmSTRING_DEFAULT_CHARSET, &text);
HT_SetNodeData (node, column_data->token, column_data->token_type,
text);
}
}
void
XFE_RDFTreeView::select_cb(Widget,
XtPointer clientData,
XtPointer callData)
{
XFE_RDFTreeView *obj = (XFE_RDFTreeView*)clientData;
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct *)callData;
D(fprintf(stderr,"select_cb(%d)\n",cbs->row););
obj->select_row(cbs->row);
}
void
XFE_RDFTreeView::select_row(int row)
{
HT_Resource node = HT_GetNthItem(_ht_rdfView, row);
if (!node) return;
HT_SetSelection(node);
}
void
XFE_RDFTreeView::deselect_cb(Widget,
XtPointer clientData,
XtPointer callData)
{
XFE_RDFTreeView *obj = (XFE_RDFTreeView*)clientData;
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct *)callData;
D(fprintf(stderr,"deselect_cb(%d)\n",cbs->row););
obj->deselect_row(cbs->row);
}
void
XFE_RDFTreeView::deselect_row(int row)
{
HT_Resource node = HT_GetNthItem(_ht_rdfView, row);
if (!node) return;
HT_SetSelectedState(node,False);
}
//////////////////////////////////////////////////////////////////////////
void
XFE_RDFTreeView::notify(HT_Notification /* ns */, HT_Resource n,
HT_Event whatHappened)
{
switch (whatHappened) {
case HT_EVENT_NODE_ADDED:
D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_NODE_ADDED",
HT_GetNodeName(n)););
add_row(n);
break;
case HT_EVENT_NODE_DELETED_DATA:
D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_NODE_DELETED_DATA",
HT_GetNodeName(n)););
break;
case HT_EVENT_NODE_DELETED_NODATA:
{
D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_NODE_DELETED_NODATA",
HT_GetNodeName(n)););
#ifdef UNDEF
// Is this a container node?
Boolean expands = HT_IsContainer(n);
PRBool isExpanded = False;
// Is the node expanded?
if (expands) {
HT_GetOpenState(n, &isExpanded);
}
int row = HT_GetNodeIndex(_ht_rdfView, n);
delete_row(row);
#endif /* UNDEF */
break;
}
case HT_EVENT_NODE_VPROP_CHANGED:
D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_NODE_VPROP_CHANGED",
HT_GetNodeName(n)););
break;
case HT_EVENT_NODE_SELECTION_CHANGED:
D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_NODE_SELECTION_CHANGED",
HT_GetNodeName(n)););
break;
case HT_EVENT_NODE_OPENCLOSE_CHANGED:
{
D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_NODE_OPENCLOSE_CHANGED",
HT_GetNodeName(n)););
refresh(n);
Boolean expands = HT_IsContainer(n);
if (expands)
{
PRBool isExpanded = False;
HT_GetOpenState(n, &isExpanded);
int row = HT_GetNodeIndex(_ht_rdfView, n);
if (isExpanded) // The node has been opened
{
// Expand the row
XtVaSetValues(m_widget, XmNrow, row,
XmNrowIsExpanded, True, NULL);
}
else
{
// collapse the row
XtVaSetValues(m_widget, XmNrow, row,
XmNrowIsExpanded, False, NULL);
}
}
break;
}
case HT_EVENT_VIEW_CLOSED:
D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_VIEW_CLOSED",
HT_GetNodeName(n)););
break;
case HT_EVENT_VIEW_SELECTED:
{
XP_ASSERT( 0 );
//
// Handled in XFE_RDFView
//
// D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_VIEW_SELECTED",
// HT_GetNodeName(n)););
// HT_View view = HT_GetView(n);
// char * label = HT_GetViewName(view);
// if (_ht_rdfView != view) {
// XtVaSetValues (viewName,
// XmNlabelString, XmStringCreateLocalized(label),
// NULL);
// }
// if (_ht_rdfView != view)
// setHTView(view);
}
break;
case HT_EVENT_NODE_OPENCLOSE_CHANGING:
{
D(printf("RDFView::HT_Event: %s on %s\n","HT_EVENT_NODE_OPENCLOSE_CHANGING",
HT_GetNodeName(n)););
break;
}
case HT_EVENT_VIEW_REFRESH:
{
int row = HT_GetNodeIndex(_ht_rdfView, n);
PRBool expands = HT_IsContainer(n);
PRBool isExpanded = False;
if (expands)
HT_GetOpenState(n, &isExpanded);
if (expands && isExpanded)
XmLTreeDeleteChildren(m_widget, row);
refresh(n);
break;
}
default:
D(printf("RDFView::HT_Event: Unknown type on %s\n",HT_GetNodeName(n)););
break;
}
}
//////////////////////////////////////////////////////////////////////
void
XFE_RDFTreeView::setHTView(HT_View htview)
{
if (htview == _ht_rdfView)
{
return;
}
_ht_rdfView = htview;
if (!_ht_rdfView)
{
return;
}
fill_tree();
}
//////////////////////////////////////////////////////////////////////
HT_View
XFE_RDFTreeView::getHTView()
{
return _ht_rdfView;
}
//////////////////////////////////////////////////////////////////////
void
XFE_RDFTreeView::fill_tree()
{
XP_ASSERT(m_widget);
if (!_ht_rdfView || !m_widget)
return;
int
item_count = HT_GetItemListCount(_ht_rdfView);
XtVaSetValues(m_widget,
XmNlayoutFrozen, True,
XmNcolumns, 1,
NULL);
XmLGridDeleteAllRows(m_widget, XmCONTENT);
// Set default values for column headings
// (Should make so that the grid widget has separate defaults
// for headings and content cells)
XtVaSetValues(m_widget,
XmNcellDefaults, True,
XmNcellLeftBorderType, XmBORDER_LINE,
XmNcellRightBorderType, XmBORDER_LINE,
XmNcellTopBorderType, XmBORDER_LINE,
XmNcellBottomBorderType, XmBORDER_LINE,
NULL);
// add columns
char *column_name;
uint32 column_width;
void *token;
uint32 token_type;
int ii = 0;
HT_Cursor column_cursor = HT_NewColumnCursor (_ht_rdfView);
while (HT_GetNextColumn(column_cursor, &column_name, &column_width,
&token, &token_type)) {
add_column(ii, column_name, column_width, token, token_type);
ii++;
}
HT_DeleteColumnCursor(column_cursor);
// Set default values for new content cells
XtVaSetValues(m_widget,
XmNcellDefaults, True,
XmNcellMarginLeft, 1,
XmNcellMarginRight, 1,
XmNcellLeftBorderType, XmBORDER_NONE,
XmNcellRightBorderType, XmBORDER_NONE,
XmNcellTopBorderType, XmBORDER_NONE,
XmNcellBottomBorderType, XmBORDER_NONE,
NULL);
// add rows
for (ii=0; ii < item_count; ii++) {
add_row(ii);
}
XtVaSetValues(m_widget,
XmNlayoutFrozen, False,
NULL);
}
void
XFE_RDFTreeView::destroy_tree()
{
}
void
XFE_RDFTreeView::add_row(int row)
{
HT_Resource node = HT_GetNthItem (_ht_rdfView, row);
add_row(node);
}
void
XFE_RDFTreeView::add_row
(HT_Resource node)
{
//HT_Resource node = GetNthItem (_ht_rdfView, row);
int row = HT_GetNodeIndex(_ht_rdfView, node);
char *name = HT_GetNodeName(node);
int depth = HT_GetItemIndentation(node);
Boolean expands = HT_IsContainer(node);
Boolean isExpanded = HT_IsContainerOpen(node);
/*D( fprintf(stderr,"XFE_RDFTreeView::add_row(0x%x %d) name(%s) depth(%d)\n",
node,row, name, depth);)*/
Pixmap pixmap, mask;
//pixmap = XmUNSPECIFIED_PIXMAP;
//pixmask = XmUNSPECIFIED_PIXMAP;
if (expands && isExpanded) {
pixmap = openedFolder.pixmap;
mask = openedFolder.mask;
} else if (expands && !isExpanded) {
pixmap = closedFolder.pixmap;
mask = closedFolder.mask;
} else {
pixmap = bookmark.pixmap;
mask = bookmark.mask;
}
XmString xmstr = XmStringCreateSimple(name);
XmLTreeAddRow(m_widget,
depth,
expands,
isExpanded,
row,
pixmap,
mask,
xmstr);
XmStringFree(xmstr);
int column_count;
// Should only need to do this for visible columns
XtVaGetValues(m_widget, XmNcolumns, &column_count, NULL);
RDFColumnData *column_data;
void *data;
for (int ii = 0; ii < column_count; ii++)
{
XmLGridColumn column = XmLGridGetColumn(m_widget, XmCONTENT, ii);
XtVaGetValues(m_widget,
XmNcolumnPtr, column,
XmNcolumnUserData, &column_data,
NULL);
Boolean is_editable = HT_IsNodeDataEditable(node,
column_data->token,
column_data->token_type);
XtVaSetValues(m_widget,
XmNrow, row,
XmNcolumn, ii,
XmNcellEditable, is_editable,
NULL);
if (HT_GetNodeData (node, column_data->token,
column_data->token_type, &data)
&& data)
{
time_t dateVal;
struct tm* time;
char buffer[200];
switch (column_data->token_type)
{
case HT_COLUMN_DATE_STRING:
if ((dateVal = (time_t)atol((char *)data)) == 0) break;
if ((time = localtime(&dateVal)) == NULL) break;
HTFE_MakePrettyDate(buffer, dateVal);
break;
case HT_COLUMN_DATE_INT:
if ((time = localtime((time_t *) &data)) == NULL) break;
HTFE_MakePrettyDate(buffer, (time_t)data);
break;
case HT_COLUMN_INT:
sprintf(buffer,"%d",(int)data);
break;
case HT_COLUMN_STRING:
strcpy(buffer, (char*)data);
break;
}
/*D(fprintf(stderr,"Node data (%d, %d) = '%s'\n",row,ii,buffer););*/
XmLGridSetStringsPos(m_widget,
XmCONTENT, row,
XmCONTENT, ii,
buffer);
}
else
{
/*D(fprintf(stderr,"No column data r(%d) c(%d) type(%d)\n",row,ii,
column_data->token_type););*/
}
}
}
void
XFE_RDFTreeView::delete_row(int row)
{
XmLGridDeleteRows(m_widget, XmCONTENT, row, 1);
}
void
XFE_RDFTreeView::add_column(int index, char *name, uint32 width,
void *token, uint32 token_type)
{
D( fprintf(stderr,"XFE_RDFTreeView::add_column index(%d) name(%s) width(%d)\n",
index, name,width););
if (index > 0) {
XmLGridAddColumns(m_widget, XmCONTENT, index, 1);
}
RDFColumnData *column_data = new RDFColumnData(token, token_type);
XtVaSetValues(m_widget,
XmNcolumn, index,
XmNcolumnSizePolicy, XmCONSTANT,
XmNcolumnWidth, width,
XmNcolumnUserData, column_data,
NULL);
XmLGridSetStringsPos(m_widget,
XmHEADING, 0,
XmCONTENT, index,
name);
}
void
XFE_RDFTreeView::delete_column(HT_Resource /* cursor */)
{
}
void
XFE_RDFTreeView::expand_row_cb(Widget,
XtPointer clientData,
XtPointer callData)
{
XFE_RDFTreeView *obj = (XFE_RDFTreeView*)clientData;
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct *)callData;
D(fprintf(stderr,"expand_row_cb(%d)\n",cbs->row););
obj->expand_row(cbs->row);
}
void
XFE_RDFTreeView::expand_row(int row)
{
HT_Resource node = HT_GetNthItem (_ht_rdfView, row);
HT_SetOpenState (node, (PRBool)TRUE);
}
void
XFE_RDFTreeView::collapse_row_cb(Widget,
XtPointer clientData,
XtPointer callData)
{
XFE_RDFTreeView *obj = (XFE_RDFTreeView*)clientData;
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct *)callData;
D(fprintf(stderr,"collapse_row_cb(%d)\n",cbs->row););
obj->collapse_row(cbs->row);
}
void
XFE_RDFTreeView::collapse_row(int row)
{
HT_Resource node = HT_GetNthItem (_ht_rdfView, row);
HT_SetOpenState (node, (PRBool)FALSE);
}
void
XFE_RDFTreeView::delete_cb(Widget w,
XtPointer /*clientData*/,
XtPointer callData)
{
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct *)callData;
XmLGridColumn column;
RDFColumnData *column_data = NULL;
cbs = (XmLGridCallbackStruct *)callData;
if (cbs->reason != XmCR_DELETE_COLUMN)
return;
column = XmLGridGetColumn(w, XmCONTENT, cbs->column);
XtVaGetValues(w,
XmNcolumnPtr, column,
XmNcolumnUserData, &column_data,
NULL);
delete column_data;
}
void
XFE_RDFTreeView::activate_cb(Widget,
XtPointer clientData,
XtPointer callData)
{
XFE_RDFTreeView *obj = (XFE_RDFTreeView*)clientData;
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct *)callData;
if (cbs->rowType != XmCONTENT)
return;
obj->activate_row(cbs->row);
}
//
// Popup menu stuff
//
void
XFE_RDFTreeView::popup_cb(Widget,
XtPointer clientData,
XtPointer callData)
{
XFE_RDFTreeView *obj = (XFE_RDFTreeView*)clientData;
XmLGridCallbackStruct *cbs = (XmLGridCallbackStruct *)callData;
if (cbs->rowType != XmCONTENT)
return;
obj->doPopup(cbs->event);
}
//////////////////////////////////////////////////////////////////////////
void
XFE_RDFTreeView::doPopup(XEvent * event)
{
if (_popup)
{
delete _popup; //destroy the old one first
}
_popup = new XFE_RDFPopupMenu("popup",
//getFrame(),
FE_GetToplevelWidget(),
_ht_rdfView,
FALSE, // not isWorkspace
FALSE); // no background commands for now
_popup->position(event);
_popup->show();
}
//////////////////////////////////////////////////////////////////////////
XFE_RDFPopupMenu::XFE_RDFPopupMenu(String name, Widget parent,
HT_View view,
Boolean isWorkspace, Boolean isBackground)
: XFE_SimplePopupMenu(name, parent)
{
m_pane = HT_GetPane(view);
HT_Cursor cursor = HT_NewContextualMenuCursor(view, isWorkspace, isBackground);
HT_MenuCmd command;
while(HT_NextContextMenuItem(cursor, &command))
{
if (command == HT_CMD_SEPARATOR)
addSeparator();
else
addPushButton(HT_GetMenuCmdName(command), (XtPointer)command,
HT_IsMenuCmdEnabled(m_pane, command));
}
}
void
XFE_RDFPopupMenu::PushButtonActivate(Widget /* w */, XtPointer userData)
{
HT_DoMenuCmd(m_pane, (HT_MenuCmd)(int)userData);
}
//////////////////////////////////////////////////////////////////////////
//
// Toggle the stand alone state
//
//////////////////////////////////////////////////////////////////////////
void
XFE_RDFTreeView::setStandAloneState(XP_Bool state)
{
XP_ASSERT( XfeIsAlive(m_widget) );
_standAloneState = state;
int visibleColumns = (_standAloneState ? 0 : 1);
XtVaSetValues(m_widget,
XmNvisibleColumns, visibleColumns,
NULL);
}
//////////////////////////////////////////////////////////////////////////
XP_Bool
XFE_RDFTreeView::getStandAloneState()
{
return _standAloneState;
}
//////////////////////////////////////////////////////////////////////////

153
cmd/xfe/src/RDFTreeView.h Normal file
Просмотреть файл

@ -0,0 +1,153 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*----------------------------------------------------------------------*/
/* */
/* Name: RDFTreeView.h */
/* Description: XFE_RDFTreeView component header file - A class to */
/* encapsulate and rdf tree widget. */
/* Author: Ramiro Estrugo <ramiro@netscape.com> */
/* */
/*----------------------------------------------------------------------*/
#ifndef _xfe_rdf_tree_view_h_
#define _xfe_rdf_tree_view_h_
#include "View.h"
#include "IconGroup.h"
#include "htrdf.h"
#include "NavCenterView.h"
#include "PopupMenu.h"
class XFE_RDFPopupMenu : public XFE_SimplePopupMenu
{
public:
XFE_RDFPopupMenu(String name, Widget parent,
HT_View view,
Boolean isWorkspace, Boolean isBackground);
void PushButtonActivate(Widget w, XtPointer userData);
protected:
HT_Pane m_pane;
};
class XFE_RDFTreeView : public XFE_View
{
public:
XFE_RDFTreeView(XFE_Component *toplevel, Widget parent,
XFE_View *parent_view, MWContext *context);
~XFE_RDFTreeView();
// Get tooltipString & docString;
// returned string shall be freed by the callee
// row < 0 indicates heading row; otherwise it is a content row
// (starting from 0)
//
virtual char *getCellTipString(int /* row */, int /* column */) {return NULL;}
virtual char *getCellDocString(int /* row */, int /* column */) {return NULL;}
// Refresh the outliner
void refresh(HT_Resource node);
// Open properties dialog
//void openPropertiesWindow();
//void closePropertiesWindow();
// RDF Specific calls
void notify(HT_Notification ns, HT_Resource n, HT_Event whatHappened);
void doPopup(XEvent *event);
// HT view set/get methods
void setHTView(HT_View view);
HT_View getHTView();
// Stand alone set/get methods
void setStandAloneState(XP_Bool state);
XP_Bool getStandAloneState();
private:
// The view as registered in the hypertree
HT_View _ht_rdfView;
// The popup menu
XFE_RDFPopupMenu * _popup;
// Is this a stand alone view ?
XP_Bool _standAloneState;
// icons for use in the bookmark window.
static fe_icon bookmark;
static fe_icon openedFolder;
static fe_icon closedFolder;
void init_pixmaps();
void fill_tree();
void destroy_tree();
void add_row(HT_Resource node);
void add_row(int node);
void delete_row(int row);
void add_column(int index, char *name, uint32 width,
void *token, uint32 token_type);
void expand_row(int row);
void collapse_row(int row);
void delete_column(HT_Resource cursor);
void activate_row(int row);
void resize(XtPointer);
void edit_cell(XtPointer);
void select_row(int row);
void deselect_row(int row);
static void expand_row_cb(Widget, XtPointer, XtPointer);
static void collapse_row_cb(Widget, XtPointer, XtPointer);
static void delete_cb(Widget, XtPointer, XtPointer);
static void activate_cb(Widget, XtPointer, XtPointer);
static void resize_cb(Widget, XtPointer, XtPointer);
static void edit_cell_cb(Widget, XtPointer, XtPointer);
static void deselect_cb(Widget, XtPointer, XtPointer);
static void select_cb(Widget, XtPointer, XtPointer);
static void popup_cb(Widget, XtPointer, XtPointer);
#ifdef NOTYET
void dropfunc(Widget dropw, fe_dnd_Event type, fe_dnd_Source *source, XEvent *event);
static void drop_func(Widget dropw, void *closure, fe_dnd_Event type,
fe_dnd_Source *source, XEvent* event);
static fe_icon mailBookmark;
static fe_icon newsBookmark;
static fe_icon changedBookmark;
// static fe_icon unknownBookmark;
static fe_icon closedPersonalFolder;
static fe_icon openedPersonalFolder;
static fe_icon closedFolderDest;
static fe_icon openedFolderDest;
static fe_icon closedFolderMenu;
static fe_icon openedFolderMenu;
static fe_icon closedFolderMenuDest;
static fe_icon openedFolderMenuDest;
#endif /*NOTYET*/
};
#endif // _xfe_rdf_tree_view_h_

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -29,24 +29,12 @@
#include "IconGroup.h"
#include "htrdf.h"
#include "NavCenterView.h"
#include "PopupMenu.h"
class XFE_RDFPopupMenu : public XFE_SimplePopupMenu
{
public:
XFE_RDFPopupMenu(String name, Widget parent,
HT_View view,
Boolean isWorkspace, Boolean isBackground);
void PushButtonActivate(Widget w, XtPointer userData);
protected:
HT_Pane m_pane;
};
#include "RDFTreeView.h"
class XFE_RDFView : public XFE_View
{
public:
XFE_RDFView(XFE_Component *toplevel, Widget parent,
XFE_View *parent_view, MWContext *context);
@ -70,78 +58,40 @@ public:
// RDF Specific calls
void notify(HT_Notification ns, HT_Resource n, HT_Event whatHappened);
void setRDFView(HT_View view);
void doPopup(XEvent *event);
// HT view set/get methods
void setHTView(HT_View view);
// Stand alone set/get methods
void setStandAloneState(XP_Bool state);
XP_Bool getStandAloneState();
private:
//HT_Pane m_Pane; // The pane that owns this view
HT_View m_rdfview; // The view as registered in the hypertree
Widget viewName; // The label that displays the currently open pane
Widget rdfControlsParent; // Parent of the label and the button on top
Widget m_tree; // The tree widget
XFE_RDFPopupMenu *m_popup;
// The view as registered in the hypertree
HT_View _ht_rdfView;
// The label that displays the currently open pane
Widget _viewLabel;
// Parent of the label and the button on top
Widget _controlToolBar;
// Toggle tree operating mode
Widget _addBookmarkControl;
// Close the view
Widget _closeControl;
// Toggle tree operating mode
Widget _modeControl;
// The rdf tree view component
XFE_RDFTreeView * _rdfTreeView;
// Is this a stand alone view ?
XP_Bool _standAloneState;
XP_Bool _standAloneState;
// icons for use in the bookmark window.
static fe_icon bookmark;
static fe_icon openedFolder;
static fe_icon closedFolder;
void init_pixmaps();
void fill_tree();
void destroy_tree();
void add_row(HT_Resource node);
void add_row(int node);
void delete_row(int row);
void add_column(int index, char *name, uint32 width,
void *token, uint32 token_type);
void expand_row(int row);
void collapse_row(int row);
void delete_column(HT_Resource cursor);
void activate_row(int row);
void resize(XtPointer);
void edit_cell(XtPointer);
void select_row(int row);
void deselect_row(int row);
static void expand_row_cb(Widget, XtPointer, XtPointer);
static void collapse_row_cb(Widget, XtPointer, XtPointer);
static void delete_cb(Widget, XtPointer, XtPointer);
static void activate_cb(Widget, XtPointer, XtPointer);
static void resize_cb(Widget, XtPointer, XtPointer);
static void edit_cell_cb(Widget, XtPointer, XtPointer);
static void deselect_cb(Widget, XtPointer, XtPointer);
static void select_cb(Widget, XtPointer, XtPointer);
static void popup_cb(Widget, XtPointer, XtPointer);
static void closeRdfView_cb(Widget, XtPointer, XtPointer);
#ifdef NOTYET
void dropfunc(Widget dropw, fe_dnd_Event type, fe_dnd_Source *source, XEvent *event);
static void drop_func(Widget dropw, void *closure, fe_dnd_Event type,
fe_dnd_Source *source, XEvent* event);
static fe_icon mailBookmark;
static fe_icon newsBookmark;
static fe_icon changedBookmark;
// static fe_icon unknownBookmark;
static fe_icon closedPersonalFolder;
static fe_icon openedPersonalFolder;
static fe_icon closedFolderDest;
static fe_icon openedFolderDest;
static fe_icon closedFolderMenu;
static fe_icon openedFolderMenu;
static fe_icon closedFolderMenuDest;
static fe_icon openedFolderMenuDest;
#endif /*NOTYET*/
static void closeRdfView_cb(Widget, XtPointer, XtPointer);
};
#endif /* _xfe_rdfview_h */