зеркало из https://github.com/mozilla/gecko-dev.git
Initial checkin of the tree widget and the data model architecture (that will
be used for toolbars and trees).
This commit is contained in:
Родитель
1e5cac4885
Коммит
eea32baf14
|
@ -27,8 +27,15 @@ CPPSRCS = \
|
||||||
nsMenuButton.cpp \
|
nsMenuButton.cpp \
|
||||||
nsToolbarItemHolder.cpp \
|
nsToolbarItemHolder.cpp \
|
||||||
nsToolbarManager.cpp \
|
nsToolbarManager.cpp \
|
||||||
nsImageButton.cpp \
|
|
||||||
nsToolBar.cpp \
|
nsToolBar.cpp \
|
||||||
|
nsHTColumn.cpp \
|
||||||
|
nsHTControlStripItem.cpp \
|
||||||
|
nsHTTreeItem.cpp \
|
||||||
|
nsHTItem.cpp \
|
||||||
|
nsHTTreeDataModel.cpp \
|
||||||
|
nsHTDataModel.cpp \
|
||||||
|
nsTreeView.cpp \
|
||||||
|
nsImageButton.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
MODULE=raptor
|
MODULE=raptor
|
||||||
|
@ -39,6 +46,13 @@ OBJS=.\$(OBJDIR)\nsBaseWidget.obj \
|
||||||
.\$(OBJDIR)\nsToolbarManager.obj \
|
.\$(OBJDIR)\nsToolbarManager.obj \
|
||||||
.\$(OBJDIR)\nsImageButton.obj \
|
.\$(OBJDIR)\nsImageButton.obj \
|
||||||
.\$(OBJDIR)\nsToolBar.obj \
|
.\$(OBJDIR)\nsToolBar.obj \
|
||||||
|
.\$(OBJDIR)\nsHTColumn.obj \
|
||||||
|
.\$(OBJDIR)\nsHTControlStripItem.obj \
|
||||||
|
.\$(OBJDIR)\nsHTTreeItem.obj \
|
||||||
|
.\$(OBJDIR)\nsHTItem.obj \
|
||||||
|
.\$(OBJDIR)\nsHTTreeDataModel.obj \
|
||||||
|
.\$(OBJDIR)\nsHTDataModel.obj \
|
||||||
|
.\$(OBJDIR)\nsTreeView.obj \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
LINCS= \
|
LINCS= \
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsDataModelWidget_h___
|
||||||
|
#define nsDataModelWidget_h___
|
||||||
|
|
||||||
|
#include "nsWindow.h"
|
||||||
|
|
||||||
|
// Events
|
||||||
|
const int cDMImageLoaded = 0;
|
||||||
|
|
||||||
|
class nsDataModelWidget : public ChildWindow
|
||||||
|
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
nsDataModelWidget() {};
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~nsDataModelWidget() {};
|
||||||
|
|
||||||
|
virtual void HandleDataModelEvent(int event, nsHierarchicalDataItem* pItem) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nspr.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsTreeColumn.h"
|
||||||
|
#include "nsHTColumn.h"
|
||||||
|
|
||||||
|
nsHTColumn::nsHTColumn() : nsTreeColumn()
|
||||||
|
{
|
||||||
|
mPixelWidth = 25;
|
||||||
|
mDesiredPercentage = 0.33;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
nsHTColumn::~nsHTColumn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TreeColumn Implementation ---------------------
|
||||||
|
int nsHTColumn::GetPixelWidth() const
|
||||||
|
{
|
||||||
|
return mPixelWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
double nsHTColumn::GetDesiredPercentage() const
|
||||||
|
{
|
||||||
|
return mDesiredPercentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTColumn::GetColumnName(nsString& name) const
|
||||||
|
{
|
||||||
|
name = "Header";
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsHTColumn::IsSortColumn() const
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTColumn::SetPixelWidth(int newWidth)
|
||||||
|
{
|
||||||
|
mPixelWidth = newWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTColumn::SetDesiredPercentage(double newPercentage)
|
||||||
|
{
|
||||||
|
mDesiredPercentage = newPercentage;
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsHTColumn_h___
|
||||||
|
#define nsHTColumn_h___
|
||||||
|
|
||||||
|
#include "nsTreeColumn.h"
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// This class functions as the data source for column information (things like
|
||||||
|
// width, desired percentage, and sorting).
|
||||||
|
|
||||||
|
class nsHTColumn : public nsTreeColumn
|
||||||
|
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsHTColumn();
|
||||||
|
virtual ~nsHTColumn();
|
||||||
|
|
||||||
|
// Inspectors
|
||||||
|
virtual int GetPixelWidth() const;
|
||||||
|
virtual double GetDesiredPercentage() const;
|
||||||
|
virtual PRBool IsSortColumn() const;
|
||||||
|
virtual void GetColumnName(nsString& name) const;
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
virtual void SetPixelWidth(int newWidth);
|
||||||
|
virtual void SetDesiredPercentage(double newPercentage);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int mPixelWidth;
|
||||||
|
double mDesiredPercentage;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsHTColumn_h___ */
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nspr.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsHTControlStripItem.h"
|
||||||
|
|
||||||
|
nsHTControlStripItem::nsHTControlStripItem() : nsTreeControlStripItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTControlStripItem::GetText(nsString& text) const
|
||||||
|
{
|
||||||
|
text = "Blah";
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsHTControlStripItem_h___
|
||||||
|
#define nsHTControlStripItem_h___
|
||||||
|
|
||||||
|
#include "nsTreeControlStripItem.h"
|
||||||
|
|
||||||
|
class nsHTControlStripItem : public nsTreeControlStripItem
|
||||||
|
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsHTControlStripItem();
|
||||||
|
virtual ~nsHTControlStripItem() {};
|
||||||
|
|
||||||
|
virtual void GetText(nsString& text) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsHTControlStripItem_h___ */
|
|
@ -0,0 +1,96 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nspr.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsFont.h"
|
||||||
|
#include "nsHTTreeDataModel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsDataModelWidget.h"
|
||||||
|
#include "nsTreeColumn.h"
|
||||||
|
#include "nsHTTreeItem.h"
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
|
||||||
|
nsHTDataModel::nsHTDataModel()
|
||||||
|
{
|
||||||
|
mListener = nsnull;
|
||||||
|
mImageGroup = nsnull;
|
||||||
|
|
||||||
|
// Init. one of our hard-coded values
|
||||||
|
mSingleNode = new nsHTTreeItem(); // TODO: This is all ridiculously illegal.
|
||||||
|
((nsHTTreeItem*)mSingleNode)->SetDataModel((nsHTTreeDataModel*)this); // This is very bad. Just doing to test.
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
nsHTDataModel::~nsHTDataModel()
|
||||||
|
{
|
||||||
|
if (mImageGroup)
|
||||||
|
{
|
||||||
|
mImageGroup->Interrupt();
|
||||||
|
NS_RELEASE(mImageGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete hard-coded value
|
||||||
|
delete mSingleNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTDataModel::SetDataModelListenerDelegate(nsDataModelWidget* pWidget)
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mImageGroup);
|
||||||
|
mListener = pWidget;
|
||||||
|
if (pWidget != nsnull && NS_NewImageGroup(&mImageGroup) == NS_OK)
|
||||||
|
{
|
||||||
|
nsIDeviceContext * deviceCtx = pWidget->GetDeviceContext();
|
||||||
|
mImageGroup->Init(deviceCtx, nsnull);
|
||||||
|
NS_RELEASE(deviceCtx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hierarchical Data Model Implementation ---------------------
|
||||||
|
|
||||||
|
|
||||||
|
nsHierarchicalDataItem* nsHTDataModel::GetRootDelegate() const
|
||||||
|
{
|
||||||
|
return (nsHTTreeItem*)mSingleNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PRUint32 nsHTDataModel::GetFirstVisibleItemIndexDelegate() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTDataModel::SetFirstVisibleItemIndexDelegate(PRUint32 n)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
nsHierarchicalDataItem* nsHTDataModel::GetNthItemDelegate(PRUint32 n) const
|
||||||
|
{
|
||||||
|
return (nsHTTreeItem*)mSingleNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTDataModel::ImageLoaded(nsHierarchicalDataItem* pItem)
|
||||||
|
{
|
||||||
|
if (mListener)
|
||||||
|
{
|
||||||
|
// Send it on along. Let the view know what happened.
|
||||||
|
mListener->HandleDataModelEvent(cDMImageLoaded, pItem);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsHTDataModel_h___
|
||||||
|
#define nsHTDataModel_h___
|
||||||
|
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsHierarchicalDataModel.h"
|
||||||
|
#include "nsIImageGroup.h"
|
||||||
|
|
||||||
|
class nsDataModelWidget;
|
||||||
|
class nsHTItem;
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// The HyperTree Base Class
|
||||||
|
// This class is a simplified API that wraps calls into the DOM
|
||||||
|
// interfaces. It is shared by the HT Tree Widget and the HT
|
||||||
|
// Toolbar.
|
||||||
|
// -----------------------------------------------------------
|
||||||
|
|
||||||
|
class nsHTDataModel
|
||||||
|
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsHTDataModel();
|
||||||
|
virtual ~nsHTDataModel();
|
||||||
|
|
||||||
|
// Retrieve the root node of the data model.
|
||||||
|
virtual nsHierarchicalDataItem* GetRootDelegate() const;
|
||||||
|
|
||||||
|
// A visibility hint can be stored and retrieved (e.g., the leftmost or topmost
|
||||||
|
// item in the current scrolled view).
|
||||||
|
virtual PRUint32 GetFirstVisibleItemIndexDelegate() const;
|
||||||
|
virtual void SetFirstVisibleItemIndexDelegate(PRUint32 index);
|
||||||
|
virtual nsHierarchicalDataItem* GetNthItemDelegate(PRUint32 n) const;
|
||||||
|
|
||||||
|
virtual void SetDataModelListenerDelegate(nsDataModelWidget* pListener);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void ImageLoaded(nsHierarchicalDataItem* pItem);
|
||||||
|
nsIImageGroup* GetImageGroup() const { NS_ADDREF(mImageGroup); return mImageGroup; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsDataModelWidget* mListener; // Events are sent to the listening widget.
|
||||||
|
nsIImageGroup* mImageGroup; // Image group used for loading all images in the model.
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Hard-coded values for testing. Will go away.
|
||||||
|
nsHTItem* mSingleNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsToolbar_h___ */
|
|
@ -0,0 +1,40 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nspr.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsHTItem.h"
|
||||||
|
|
||||||
|
nsHTItem::nsHTItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
nsHTItem::~nsHTItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsHTItem::IsExpandedDelegate() const
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRUint32 nsHTItem::GetIndentationLevelDelegate() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsHTItem_h___
|
||||||
|
#define nsHTItem_h___
|
||||||
|
|
||||||
|
class nsHierarchicalDataModel;
|
||||||
|
|
||||||
|
class nsHTItem
|
||||||
|
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsHTItem();
|
||||||
|
virtual ~nsHTItem();
|
||||||
|
|
||||||
|
virtual PRBool IsExpandedDelegate() const;
|
||||||
|
virtual PRUint32 GetIndentationLevelDelegate() const;
|
||||||
|
|
||||||
|
virtual void SetDataModelDelegate(nsHierarchicalDataModel* pDataModel) { mDataModel = pDataModel; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsHierarchicalDataModel* mDataModel;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsHTItem_h___ */
|
|
@ -0,0 +1,284 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nspr.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsFont.h"
|
||||||
|
#include "nsHTTreeDataModel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsDataModelWidget.h"
|
||||||
|
#include "nsHTColumn.h"
|
||||||
|
#include "nsHTControlStripItem.h"
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
#include "nsIImageObserver.h"
|
||||||
|
#include "nsIImageRequest.h"
|
||||||
|
#include "nsIImageGroup.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
static NS_DEFINE_IID(kIImageObserverIID, NS_IIMAGEREQUESTOBSERVER_IID);
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsHTTreeDataModel)
|
||||||
|
NS_IMPL_RELEASE(nsHTTreeDataModel)
|
||||||
|
|
||||||
|
nsHTTreeDataModel::nsHTTreeDataModel() : nsTreeDataModel(), nsHTDataModel()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
|
||||||
|
// Image Request Inits
|
||||||
|
mTitleBGRequest = nsnull;
|
||||||
|
mControlStripBGRequest = nsnull;
|
||||||
|
mColumnHeaderBGRequest = nsnull;
|
||||||
|
|
||||||
|
// Hard-coded values.
|
||||||
|
mVisibleColumnCount = 3;
|
||||||
|
mTotalColumnCount = 3;
|
||||||
|
mSingleColumn = new nsHTColumn();
|
||||||
|
mSecondColumn = new nsHTColumn();
|
||||||
|
mThirdColumn = new nsHTColumn();
|
||||||
|
mSingleControlStripItem = new nsHTControlStripItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
nsHTTreeDataModel::~nsHTTreeDataModel()
|
||||||
|
{
|
||||||
|
// Delete hard-coded value
|
||||||
|
delete mSingleColumn;
|
||||||
|
delete mSecondColumn;
|
||||||
|
delete mThirdColumn;
|
||||||
|
delete mSingleControlStripItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ISupports Implementation --------------------------------------------------------------------
|
||||||
|
nsresult nsHTTreeDataModel::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
if (aIID.Equals(kISupportsIID)) {
|
||||||
|
*aInstancePtr = (void*) (nsISupports *)(nsIImageRequestObserver*)this;
|
||||||
|
AddRef();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
if (aIID.Equals(kIImageObserverIID)) {
|
||||||
|
*aInstancePtr = (void*)(nsIImageRequestObserver*)this;
|
||||||
|
AddRef();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hierarchical Tree Data Model Implementation ---------------------
|
||||||
|
|
||||||
|
PRUint32 nsHTTreeDataModel::GetVisibleColumnCount() const
|
||||||
|
{
|
||||||
|
return mVisibleColumnCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRUint32 nsHTTreeDataModel::GetColumnCount() const
|
||||||
|
{
|
||||||
|
return mTotalColumnCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsTreeColumn* nsHTTreeDataModel::GetNthColumn(PRUint32 n) const
|
||||||
|
{
|
||||||
|
if (n == 0)
|
||||||
|
return mSingleColumn;
|
||||||
|
else if (n == 1)
|
||||||
|
return mSecondColumn;
|
||||||
|
else return mThirdColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeDataModel::SetVisibleColumnCount(PRUint32 columnCount)
|
||||||
|
{
|
||||||
|
mVisibleColumnCount = columnCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRUint32 nsHTTreeDataModel::GetControlStripItemCount() const
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsTreeControlStripItem* nsHTTreeDataModel::GetNthControlStripItem(PRUint32 n) const
|
||||||
|
{
|
||||||
|
return mSingleControlStripItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeDataModel::GetControlStripCloseText(nsString& closeText) const
|
||||||
|
{
|
||||||
|
closeText = "Close";
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsHTTreeDataModel::ShowTitleBar() const
|
||||||
|
{
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsHTTreeDataModel::ShowTitleBarText() const
|
||||||
|
{
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsHTTreeDataModel::ShowControlStrip() const
|
||||||
|
{
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsHTTreeDataModel::ShowColumnHeaders() const
|
||||||
|
{
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeDataModel::GetTitleBarStyle(nsIDeviceContext* dc, nsBasicStyleInfo& styleInfo) const
|
||||||
|
{
|
||||||
|
// Initialize the font.
|
||||||
|
nsString fontFamily("Haettenschweiler");
|
||||||
|
int fontSize = 24;
|
||||||
|
int fontWeight = 400;
|
||||||
|
int fontStyle = NS_FONT_STYLE_NORMAL;
|
||||||
|
int fontDecoration = NS_FONT_DECORATION_NONE;
|
||||||
|
|
||||||
|
float t2d;
|
||||||
|
dc->GetTwipsToDevUnits(t2d);
|
||||||
|
nsFont theFont(fontFamily, fontStyle, NS_FONT_VARIANT_NORMAL,
|
||||||
|
fontWeight, fontDecoration,
|
||||||
|
nscoord(t2d * NSIntPointsToTwips(fontSize)));
|
||||||
|
|
||||||
|
styleInfo.font = theFont;
|
||||||
|
|
||||||
|
// Init the colors
|
||||||
|
styleInfo.foregroundColor = NS_RGB(255,255,255);
|
||||||
|
styleInfo.backgroundColor = NS_RGB(0,0,0);
|
||||||
|
|
||||||
|
styleInfo.pBackgroundImage = GetTitleBGImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeDataModel::GetColumnHeaderStyle(nsIDeviceContext* dc, nsColumnHeaderStyleInfo& styleInfo) const
|
||||||
|
{
|
||||||
|
// Initialize the font.
|
||||||
|
nsString fontFamily("Lucida Handwriting");
|
||||||
|
int fontSize = 12;
|
||||||
|
int fontWeight = 400;
|
||||||
|
int fontStyle = NS_FONT_STYLE_NORMAL;
|
||||||
|
int fontDecoration = NS_FONT_DECORATION_NONE;
|
||||||
|
|
||||||
|
float t2d;
|
||||||
|
dc->GetTwipsToDevUnits(t2d);
|
||||||
|
nsFont theFont(fontFamily, fontStyle, NS_FONT_VARIANT_NORMAL,
|
||||||
|
fontWeight, fontDecoration,
|
||||||
|
nscoord(t2d * NSIntPointsToTwips(fontSize)));
|
||||||
|
|
||||||
|
styleInfo.font = theFont;
|
||||||
|
|
||||||
|
// Init the colors
|
||||||
|
styleInfo.foregroundColor = NS_RGB(255,255,255);
|
||||||
|
styleInfo.backgroundColor = NS_RGB(192,192,192);
|
||||||
|
styleInfo.sortFGColor = NS_RGB(0,0,0);
|
||||||
|
styleInfo.sortBGColor = NS_RGB(64,64,64);
|
||||||
|
|
||||||
|
styleInfo.pBackgroundImage = GetColumnHeaderBGImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeDataModel::GetControlStripStyle(nsIDeviceContext* dc, nsBasicStyleInfo& styleInfo) const
|
||||||
|
{
|
||||||
|
// Initialize the font.
|
||||||
|
nsString fontFamily("Arial Narrow");
|
||||||
|
int fontSize = 12;
|
||||||
|
int fontWeight = 400;
|
||||||
|
int fontStyle = NS_FONT_STYLE_NORMAL;
|
||||||
|
int fontDecoration = NS_FONT_DECORATION_NONE;
|
||||||
|
|
||||||
|
float t2d;
|
||||||
|
dc->GetTwipsToDevUnits(t2d);
|
||||||
|
nsFont theFont(fontFamily, fontStyle, NS_FONT_VARIANT_NORMAL,
|
||||||
|
fontWeight, fontDecoration,
|
||||||
|
nscoord(t2d * NSIntPointsToTwips(fontSize)));
|
||||||
|
|
||||||
|
styleInfo.font = theFont;
|
||||||
|
|
||||||
|
// Init the colors
|
||||||
|
styleInfo.foregroundColor = NS_RGB(255,255,255);
|
||||||
|
styleInfo.backgroundColor = NS_RGB(0,0,0);
|
||||||
|
|
||||||
|
styleInfo.pBackgroundImage = GetControlStripBGImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeDataModel::GetTitleBarText(nsString& text) const
|
||||||
|
{
|
||||||
|
text = "Bookmarks";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protected Helpers
|
||||||
|
nsIImage* nsHTTreeDataModel::GetTitleBGImage() const
|
||||||
|
{
|
||||||
|
nsString url("http://www.shadowland.org/images/ancient_glyphs.jpg");
|
||||||
|
if (mTitleBGRequest == nsnull)
|
||||||
|
mTitleBGRequest = RequestImage(url);
|
||||||
|
return mTitleBGRequest->GetImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIImage* nsHTTreeDataModel::GetControlStripBGImage() const
|
||||||
|
{
|
||||||
|
nsString url("http://www.shadowland.org/images/minute_bumps.jpg");
|
||||||
|
if (mControlStripBGRequest == nsnull)
|
||||||
|
mControlStripBGRequest = RequestImage(url);
|
||||||
|
return mControlStripBGRequest->GetImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIImage* nsHTTreeDataModel::GetColumnHeaderBGImage() const
|
||||||
|
{
|
||||||
|
nsString url("http://www.shadowland.org/images/tapestry.jpg");
|
||||||
|
if (mColumnHeaderBGRequest == nsnull)
|
||||||
|
mColumnHeaderBGRequest = RequestImage(url);
|
||||||
|
return mColumnHeaderBGRequest->GetImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIImageRequest* nsHTTreeDataModel::RequestImage(nsString& reqUrl) const
|
||||||
|
{
|
||||||
|
nsIImageGroup* pGroup = GetImageGroup();
|
||||||
|
|
||||||
|
char * url = reqUrl.ToNewCString();
|
||||||
|
|
||||||
|
nsIImageRequest * request;
|
||||||
|
request = pGroup->GetImage(url,
|
||||||
|
(nsIImageRequestObserver*)this,
|
||||||
|
NULL, 0, 0,
|
||||||
|
0);
|
||||||
|
delete url;
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
// image request observer implementation
|
||||||
|
void nsHTTreeDataModel::Notify(nsIImageRequest *aImageRequest,
|
||||||
|
nsIImage *aImage,
|
||||||
|
nsImageNotification aNotificationType,
|
||||||
|
PRInt32 aParam1, PRInt32 aParam2,
|
||||||
|
void *aParam3)
|
||||||
|
{
|
||||||
|
if (aNotificationType == nsImageNotification_kImageComplete)
|
||||||
|
{
|
||||||
|
// Notify the data source that we loaded. It can then inform the data source listener
|
||||||
|
// regarding what happened.
|
||||||
|
ImageLoaded(nsnull);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeDataModel::NotifyError(nsIImageRequest *aImageRequest,
|
||||||
|
nsImageError aErrorType)
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,112 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsHTTreeDataModel_h___
|
||||||
|
#define nsHTTreeDataModel_h___
|
||||||
|
|
||||||
|
#include "nsHTDataModel.h"
|
||||||
|
#include "nsTreeDataModel.h"
|
||||||
|
#include "nsIImageObserver.h"
|
||||||
|
|
||||||
|
class nsTreeColumn;
|
||||||
|
class nsTreeControlStripItem;
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// An abstract API for communication with a hierarchical store of
|
||||||
|
// information. Iteration over children in the model is provided.
|
||||||
|
// The model also provides a flattened view of the tree (a list
|
||||||
|
// of visible nodes).
|
||||||
|
//------------------------------------------------------------
|
||||||
|
|
||||||
|
class nsHTTreeDataModel : public nsHTDataModel, public nsTreeDataModel, public nsIImageRequestObserver
|
||||||
|
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsHTTreeDataModel();
|
||||||
|
virtual ~nsHTTreeDataModel();
|
||||||
|
|
||||||
|
// Isupports interface ------------------
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// IImageRequestObserver Interface ----------------
|
||||||
|
void Notify(nsIImageRequest *aImageRequest,
|
||||||
|
nsIImage *aImage,
|
||||||
|
nsImageNotification aNotificationType,
|
||||||
|
PRInt32 aParam1, PRInt32 aParam2,
|
||||||
|
void *aParam3);
|
||||||
|
|
||||||
|
void NotifyError(nsIImageRequest *aImageRequest,
|
||||||
|
nsImageError aErrorType);
|
||||||
|
// End of interfaces
|
||||||
|
|
||||||
|
// Functions inherited from abstract hierarchical data model should be delegated to our
|
||||||
|
// concrete base class
|
||||||
|
virtual nsHierarchicalDataItem* GetRoot() const { return GetRootDelegate(); }
|
||||||
|
virtual PRUint32 GetFirstVisibleItemIndex() const { return GetFirstVisibleItemIndexDelegate(); };
|
||||||
|
virtual void SetFirstVisibleItemIndex(PRUint32 index) { SetFirstVisibleItemIndexDelegate(index); };
|
||||||
|
virtual nsHierarchicalDataItem* GetNthItem(PRUint32 n) const { return GetNthItemDelegate(n) ;};
|
||||||
|
virtual void SetDataModelListener(nsDataModelWidget* pListener) { SetDataModelListenerDelegate(pListener); };
|
||||||
|
// End of delegated functions
|
||||||
|
|
||||||
|
// Column Iteration
|
||||||
|
virtual PRUint32 GetVisibleColumnCount() const;
|
||||||
|
virtual PRUint32 GetColumnCount() const;
|
||||||
|
virtual nsTreeColumn* GetNthColumn(PRUint32 n) const;
|
||||||
|
virtual void SetVisibleColumnCount(PRUint32 n);
|
||||||
|
|
||||||
|
// Control Strip Iteration
|
||||||
|
virtual PRUint32 GetControlStripItemCount() const;
|
||||||
|
virtual nsTreeControlStripItem* GetNthControlStripItem(PRUint32 n) const;
|
||||||
|
virtual void GetControlStripCloseText(nsString& closeText) const;
|
||||||
|
|
||||||
|
// Visibility Queries
|
||||||
|
virtual PRBool ShowTitleBar() const;
|
||||||
|
virtual PRBool ShowTitleBarText() const;
|
||||||
|
virtual PRBool ShowColumnHeaders() const;
|
||||||
|
virtual PRBool ShowControlStrip() const;
|
||||||
|
|
||||||
|
// Style Retrievers
|
||||||
|
virtual void GetTitleBarStyle(nsIDeviceContext* pContext,
|
||||||
|
nsBasicStyleInfo& styleInfo) const;
|
||||||
|
virtual void GetColumnHeaderStyle(nsIDeviceContext* pContext,
|
||||||
|
nsColumnHeaderStyleInfo& styleInfo) const;
|
||||||
|
virtual void GetControlStripStyle(nsIDeviceContext* pContext,
|
||||||
|
nsBasicStyleInfo& styleInfo) const;
|
||||||
|
|
||||||
|
// Text for the title bar, control strip and column headers
|
||||||
|
virtual void GetTitleBarText(nsString& text) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsIImageRequest* RequestImage(nsString& reqUrl) const; // Helper to kick off the image load.
|
||||||
|
nsIImage* GetTitleBGImage() const;
|
||||||
|
nsIImage* GetControlStripBGImage() const;
|
||||||
|
nsIImage* GetColumnHeaderBGImage() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsTreeColumn *mSingleColumn, *mSecondColumn, *mThirdColumn;
|
||||||
|
nsTreeControlStripItem *mSingleControlStripItem;
|
||||||
|
|
||||||
|
PRUint32 mVisibleColumnCount;
|
||||||
|
PRUint32 mTotalColumnCount;
|
||||||
|
mutable nsIImageRequest* mTitleBGRequest; // The title bar background image
|
||||||
|
mutable nsIImageRequest* mControlStripBGRequest;// The control strip bg image
|
||||||
|
mutable nsIImageRequest* mColumnHeaderBGRequest;// The column header background image
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsHTTreeDataModel_h___ */
|
|
@ -0,0 +1,180 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nspr.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsHTTreeItem.h"
|
||||||
|
#include "nsHTTreeDataModel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsRepository.h"
|
||||||
|
#include "nsIImageObserver.h"
|
||||||
|
#include "nsIImageRequest.h"
|
||||||
|
#include "nsIImageGroup.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
static NS_DEFINE_IID(kIImageObserverIID, NS_IIMAGEREQUESTOBSERVER_IID);
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsHTTreeItem)
|
||||||
|
NS_IMPL_RELEASE(nsHTTreeItem)
|
||||||
|
|
||||||
|
nsHTTreeItem::nsHTTreeItem() : nsTreeItem(), nsHTItem()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mClosedIconRequest = nsnull;
|
||||||
|
mOpenIconRequest = nsnull;
|
||||||
|
mClosedTriggerRequest = nsnull;
|
||||||
|
mOpenTriggerRequest = nsnull;
|
||||||
|
mBackgroundRequest = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
nsHTTreeItem::~nsHTTreeItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// ISupports Implementation --------------------------------------------------------------------
|
||||||
|
nsresult nsHTTreeItem::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
if (aIID.Equals(kISupportsIID)) {
|
||||||
|
*aInstancePtr = (void*) (nsISupports *)(nsIImageRequestObserver*)this;
|
||||||
|
AddRef();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
if (aIID.Equals(kIImageObserverIID)) {
|
||||||
|
*aInstancePtr = (void*)(nsIImageRequestObserver*)this;
|
||||||
|
AddRef();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TreeItem Implementation ---------------------
|
||||||
|
|
||||||
|
void nsHTTreeItem::GetItemStyle(nsIDeviceContext* dc, nsTreeItemStyleInfo& styleInfo) const
|
||||||
|
{
|
||||||
|
styleInfo.foregroundColor = NS_RGB(0,0,0);
|
||||||
|
styleInfo.backgroundColor = NS_RGB(240,240,240);
|
||||||
|
styleInfo.showTrigger = PR_TRUE;
|
||||||
|
styleInfo.showIcon = PR_TRUE;
|
||||||
|
styleInfo.leftJustifyTrigger = PR_FALSE;
|
||||||
|
|
||||||
|
if (styleInfo.showTrigger)
|
||||||
|
styleInfo.pTriggerImage = GetTriggerImage();
|
||||||
|
|
||||||
|
if (styleInfo.showIcon)
|
||||||
|
styleInfo.pIconImage = GetIconImage();
|
||||||
|
|
||||||
|
styleInfo.pBackgroundImage = GetBackgroundImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIImage* nsHTTreeItem::GetTriggerImage() const
|
||||||
|
{
|
||||||
|
// TODO: Really read in these properties
|
||||||
|
nsString openTriggerURL("file:///c|/Program%20Files/SL/CLIENT/IMAGES/overlay.gif");
|
||||||
|
nsString closedTriggerURL("file:///c|/Program%20Files/SL/CLIENT/IMAGES/overlay.gif");
|
||||||
|
|
||||||
|
if (IsExpanded())
|
||||||
|
{
|
||||||
|
if (mOpenTriggerRequest == nsnull)
|
||||||
|
{
|
||||||
|
// Request the image.
|
||||||
|
mOpenTriggerRequest = RequestImage(openTriggerURL);
|
||||||
|
}
|
||||||
|
return mOpenTriggerRequest->GetImage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mClosedTriggerRequest == nsnull)
|
||||||
|
mClosedTriggerRequest = RequestImage(closedTriggerURL);
|
||||||
|
return mClosedTriggerRequest->GetImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIImage* nsHTTreeItem::GetIconImage() const
|
||||||
|
{
|
||||||
|
nsString openIconURL("file:///c|/Program%20Files/SL/CLIENT/IMAGES/OpenRead.gif");
|
||||||
|
nsString closedIconURL("file:///c|/Program%20Files/SL/CLIENT/IMAGES/ClosedRead.gif");
|
||||||
|
|
||||||
|
if (IsExpanded())
|
||||||
|
{
|
||||||
|
if (mOpenIconRequest == nsnull)
|
||||||
|
mOpenIconRequest = RequestImage(openIconURL);
|
||||||
|
return mOpenIconRequest->GetImage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mClosedIconRequest == nsnull)
|
||||||
|
mClosedIconRequest = RequestImage(closedIconURL);
|
||||||
|
return mClosedIconRequest->GetImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIImage* nsHTTreeItem::GetBackgroundImage() const
|
||||||
|
{
|
||||||
|
nsString bgURL("http://www.shadowland.org/images/chalk.jpg");
|
||||||
|
if (mBackgroundRequest == nsnull)
|
||||||
|
mBackgroundRequest = RequestImage(bgURL);
|
||||||
|
return mBackgroundRequest->GetImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIImageRequest* nsHTTreeItem::RequestImage(nsString& reqUrl) const
|
||||||
|
{
|
||||||
|
nsHTTreeDataModel* pDataModel = (nsHTTreeDataModel*)(mDataModel);
|
||||||
|
nsIImageGroup* pGroup = pDataModel->GetImageGroup();
|
||||||
|
|
||||||
|
char * url = reqUrl.ToNewCString();
|
||||||
|
|
||||||
|
nsIImageRequest * request;
|
||||||
|
request = pGroup->GetImage(url,
|
||||||
|
(nsIImageRequestObserver*)this,
|
||||||
|
NULL, 0, 0,
|
||||||
|
0);
|
||||||
|
delete url;
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeItem::GetTextForColumn(nsTreeColumn* pColumn, nsString& nodeText) const
|
||||||
|
{
|
||||||
|
nodeText = "Node Stuff";
|
||||||
|
}
|
||||||
|
|
||||||
|
// image request observer implementation
|
||||||
|
void nsHTTreeItem::Notify(nsIImageRequest *aImageRequest,
|
||||||
|
nsIImage *aImage,
|
||||||
|
nsImageNotification aNotificationType,
|
||||||
|
PRInt32 aParam1, PRInt32 aParam2,
|
||||||
|
void *aParam3)
|
||||||
|
{
|
||||||
|
if (aNotificationType == nsImageNotification_kImageComplete)
|
||||||
|
{
|
||||||
|
// Notify the data source that we loaded. It can then inform the data source listener
|
||||||
|
// regarding what happened.
|
||||||
|
nsHTTreeDataModel* pDataModel = (nsHTTreeDataModel*)(mDataModel);
|
||||||
|
if (pDataModel)
|
||||||
|
pDataModel->ImageLoaded(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsHTTreeItem::NotifyError(nsIImageRequest *aImageRequest,
|
||||||
|
nsImageError aErrorType)
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsHTTreeItem_h___
|
||||||
|
#define nsHTTreeItem_h___
|
||||||
|
|
||||||
|
#include "nsTreeItem.h"
|
||||||
|
#include "nsHTItem.h"
|
||||||
|
#include "nsIImageObserver.h"
|
||||||
|
|
||||||
|
class nsHTDataModel;
|
||||||
|
class nsIImageGroup;
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// This class functions as the data source for column information (things like
|
||||||
|
// width, desired percentage, and sorting).
|
||||||
|
|
||||||
|
class nsHTTreeItem : public nsTreeItem, public nsHTItem, public nsIImageRequestObserver
|
||||||
|
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsHTTreeItem();
|
||||||
|
virtual ~nsHTTreeItem();
|
||||||
|
|
||||||
|
// Isupports interface ------------------
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// IImageRequestObserver Interface ----------------
|
||||||
|
void Notify(nsIImageRequest *aImageRequest,
|
||||||
|
nsIImage *aImage,
|
||||||
|
nsImageNotification aNotificationType,
|
||||||
|
PRInt32 aParam1, PRInt32 aParam2,
|
||||||
|
void *aParam3);
|
||||||
|
|
||||||
|
void NotifyError(nsIImageRequest *aImageRequest,
|
||||||
|
nsImageError aErrorType);
|
||||||
|
// End of interfaces
|
||||||
|
|
||||||
|
// All functions inherited from HierarchicalDataItem are delegated to
|
||||||
|
// the concrete implementation.
|
||||||
|
virtual PRBool IsExpanded() const { return IsExpandedDelegate(); };
|
||||||
|
virtual PRUint32 GetIndentationLevel() const { return GetIndentationLevelDelegate(); };
|
||||||
|
virtual void SetDataModel(nsHierarchicalDataModel* pDataModel) { SetDataModelDelegate(pDataModel); };
|
||||||
|
// End of delegated functions
|
||||||
|
|
||||||
|
virtual void GetItemStyle(nsIDeviceContext* dc,
|
||||||
|
nsTreeItemStyleInfo& styleInfo) const;
|
||||||
|
|
||||||
|
virtual void GetTextForColumn(nsTreeColumn* pColumn, nsString& nodeText) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsIImageRequest* RequestImage(nsString& reqUrl) const; // Helper to kick off the image load.
|
||||||
|
nsIImage* GetTriggerImage() const;
|
||||||
|
nsIImage* GetIconImage() const;
|
||||||
|
nsIImage* GetBackgroundImage() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mutable nsIImageRequest* mClosedIconRequest; // Closed image
|
||||||
|
mutable nsIImageRequest* mOpenIconRequest; // Open image
|
||||||
|
mutable nsIImageRequest* mClosedTriggerRequest; // Closed trigger image
|
||||||
|
mutable nsIImageRequest* mOpenTriggerRequest; // Open trigger image
|
||||||
|
mutable nsIImageRequest* mBackgroundRequest; // The background image
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsHTTreeItem_h___ */
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsHierarchicalDataItem_h___
|
||||||
|
#define nsHierarchicalDataItem_h___
|
||||||
|
|
||||||
|
class nsHierarchicalDataModel;
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// A single item in a hierarchical data model.
|
||||||
|
//------------------------------------------------------------
|
||||||
|
|
||||||
|
class nsHierarchicalDataItem
|
||||||
|
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
nsHierarchicalDataItem() {}; // Disallow instantiation of abstract class.
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~nsHierarchicalDataItem() {};
|
||||||
|
|
||||||
|
virtual PRBool IsExpanded() const = 0;
|
||||||
|
virtual PRUint32 GetIndentationLevel() const = 0;
|
||||||
|
|
||||||
|
virtual void SetDataModel(nsHierarchicalDataModel* pDataModel) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsHierarchicalDataItem_h___ */
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsHierarchicalDataModel_h___
|
||||||
|
#define nsHierarchicalDataModel_h___
|
||||||
|
|
||||||
|
class nsHierarchicalDataItem;
|
||||||
|
class nsDataModelWidget;
|
||||||
|
|
||||||
|
// Style info helper struct shared by most widgets.
|
||||||
|
struct nsBasicStyleInfo
|
||||||
|
{
|
||||||
|
nsFont font;
|
||||||
|
nscolor foregroundColor;
|
||||||
|
nscolor backgroundColor;
|
||||||
|
nsIImage* pBackgroundImage;
|
||||||
|
|
||||||
|
nsBasicStyleInfo(const nsFont& aFont)
|
||||||
|
:font(aFont)
|
||||||
|
{
|
||||||
|
pBackgroundImage = nsnull;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
// An abstract API for communication with a hierarchical store of
|
||||||
|
// information. Iteration over children in the model is provided.
|
||||||
|
// The model also provides a flattened view of the tree (a list
|
||||||
|
// of visible nodes).
|
||||||
|
//------------------------------------------------------------
|
||||||
|
|
||||||
|
class nsHierarchicalDataModel
|
||||||
|
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
nsHierarchicalDataModel() {}; // Disallow instantiation of abstract class.
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~nsHierarchicalDataModel() {};
|
||||||
|
|
||||||
|
// Retrieve the root node of the data model.
|
||||||
|
virtual nsHierarchicalDataItem* GetRoot() const = 0;
|
||||||
|
|
||||||
|
// A visibility hint can be stored and retrieved (e.g., the leftmost or topmost
|
||||||
|
// item in the current scrolled view).
|
||||||
|
virtual PRUint32 GetFirstVisibleItemIndex() const = 0;
|
||||||
|
virtual void SetFirstVisibleItemIndex(PRUint32 index) = 0;
|
||||||
|
virtual nsHierarchicalDataItem* GetNthItem(PRUint32 n) const = 0;
|
||||||
|
|
||||||
|
virtual void SetDataModelListener(nsDataModelWidget* pListener) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsHierarchicalDataModel_h___ */
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTreeColumn_h___
|
||||||
|
#define nsTreeColumn_h___
|
||||||
|
|
||||||
|
class nsTreeColumn
|
||||||
|
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
nsTreeColumn() {}; // Disallow instantiation of abstract class.
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~nsTreeColumn() {};
|
||||||
|
|
||||||
|
// Inspectors
|
||||||
|
virtual int GetPixelWidth() const = 0;
|
||||||
|
virtual double GetDesiredPercentage() const = 0;
|
||||||
|
virtual PRBool IsSortColumn() const = 0;
|
||||||
|
virtual void GetColumnName(nsString& name) const = 0;
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
virtual void SetPixelWidth(int newWidth) = 0;
|
||||||
|
virtual void SetDesiredPercentage(double newPercentage) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsTreeColumn_h___ */
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTreeControlStripItem_h___
|
||||||
|
#define nsTreeControlStripItem_h___
|
||||||
|
|
||||||
|
class nsTreeControlStripItem
|
||||||
|
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
nsTreeControlStripItem() {}; // Disallow instantiation of abstract class.
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~nsTreeControlStripItem() {};
|
||||||
|
|
||||||
|
virtual void GetText(nsString& text) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsTreeControlStripItem_h___ */
|
|
@ -0,0 +1,128 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTreeDataModel_h___
|
||||||
|
#define nsTreeDataModel_h___
|
||||||
|
|
||||||
|
#include "nsHierarchicalDataModel.h"
|
||||||
|
|
||||||
|
class nsTreeItem;
|
||||||
|
class nsTreeColumn;
|
||||||
|
class nsTreeControlStripItem;
|
||||||
|
|
||||||
|
struct nsColumnHeaderStyleInfo: public nsBasicStyleInfo
|
||||||
|
{
|
||||||
|
nscolor sortFGColor;
|
||||||
|
nscolor sortBGColor;
|
||||||
|
nsIImage* pSortBackgroundImage;
|
||||||
|
PRBool transparentSort;
|
||||||
|
nsFont sortFont;
|
||||||
|
|
||||||
|
nsColumnHeaderStyleInfo(const nsFont& aFont)
|
||||||
|
:nsBasicStyleInfo(aFont), sortFont(aFont)
|
||||||
|
{ pSortBackgroundImage = nsnull; };
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nsTreeItemStyleInfo: public nsBasicStyleInfo
|
||||||
|
{
|
||||||
|
PRBool selectWholeLine;
|
||||||
|
nscolor selectionFGColor;
|
||||||
|
nscolor selectionBGColor;
|
||||||
|
nsIImage* pSelectionBackgroundImage;
|
||||||
|
PRBool transparentSelection;
|
||||||
|
nsFont selectionFont;
|
||||||
|
|
||||||
|
PRBool rolloverWholeLine;
|
||||||
|
nscolor rolloverFGColor;
|
||||||
|
nscolor rolloverBGColor;
|
||||||
|
nsIImage* pRolloverBackgroundImage;
|
||||||
|
PRBool transparentRollover;
|
||||||
|
nsFont rolloverFont;
|
||||||
|
|
||||||
|
nscolor sortFGColor;
|
||||||
|
nscolor sortBGColor;
|
||||||
|
nsIImage* pSortBackgroundImage;
|
||||||
|
PRBool transparentSort;
|
||||||
|
nsFont sortFont;
|
||||||
|
|
||||||
|
PRBool showTrigger;
|
||||||
|
PRBool leftJustifyTrigger;
|
||||||
|
PRBool showIcon;
|
||||||
|
|
||||||
|
nsIImage* pTriggerImage;
|
||||||
|
nsIImage* pIconImage;
|
||||||
|
|
||||||
|
nscolor showHorizontalDivider;
|
||||||
|
nscolor horizontalDividerColor;
|
||||||
|
|
||||||
|
nscolor showVerticalDivider;
|
||||||
|
nscolor verticalDividerColor;
|
||||||
|
|
||||||
|
nsTreeItemStyleInfo(const nsFont& aFont)
|
||||||
|
:nsBasicStyleInfo(aFont), sortFont(aFont), selectionFont(aFont), rolloverFont(aFont)
|
||||||
|
{
|
||||||
|
pSelectionBackgroundImage = pSortBackgroundImage =
|
||||||
|
pTriggerImage = pIconImage = nsnull;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// An abstract API for communication with a hierarchical store of
|
||||||
|
// information that is designed to go into a tree widget (a widget
|
||||||
|
// with tree lines and multiple columns).
|
||||||
|
//------------------------------------------------------------
|
||||||
|
|
||||||
|
class nsTreeDataModel : public nsHierarchicalDataModel
|
||||||
|
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
nsTreeDataModel() {}; // Disallow instantiation of abstract class.
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~nsTreeDataModel() {};
|
||||||
|
|
||||||
|
// Column APIs
|
||||||
|
virtual PRUint32 GetVisibleColumnCount() const = 0;
|
||||||
|
virtual PRUint32 GetColumnCount() const = 0;
|
||||||
|
virtual nsTreeColumn* GetNthColumn(PRUint32 n) const = 0;
|
||||||
|
virtual void SetVisibleColumnCount(PRUint32 n) = 0;
|
||||||
|
|
||||||
|
// Control Strip Iteration
|
||||||
|
virtual PRUint32 GetControlStripItemCount() const = 0;
|
||||||
|
virtual nsTreeControlStripItem* GetNthControlStripItem(PRUint32 n) const = 0;
|
||||||
|
virtual void GetControlStripCloseText(nsString& closeText) const = 0;
|
||||||
|
|
||||||
|
// Visibility Queries
|
||||||
|
virtual PRBool ShowTitleBar() const = 0;
|
||||||
|
virtual PRBool ShowTitleBarText() const = 0;
|
||||||
|
virtual PRBool ShowColumnHeaders() const = 0;
|
||||||
|
virtual PRBool ShowControlStrip() const = 0;
|
||||||
|
|
||||||
|
// Style Retrievers
|
||||||
|
virtual void GetTitleBarStyle(nsIDeviceContext* pContext,
|
||||||
|
nsBasicStyleInfo& styleInfo) const = 0;
|
||||||
|
virtual void GetColumnHeaderStyle(nsIDeviceContext* pContext,
|
||||||
|
nsColumnHeaderStyleInfo& styleInfo) const = 0;
|
||||||
|
virtual void GetControlStripStyle(nsIDeviceContext* pContext,
|
||||||
|
nsBasicStyleInfo& styleInfo) const = 0;
|
||||||
|
|
||||||
|
// Text for the title bar
|
||||||
|
virtual void GetTitleBarText(nsString& text) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsTreeDataModel_h___ */
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTreeItem_h___
|
||||||
|
#define nsTreeItem_h___
|
||||||
|
|
||||||
|
class nsTreeColumn;
|
||||||
|
class nsIDeviceContext;
|
||||||
|
class nsIImage;
|
||||||
|
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsFont.h"
|
||||||
|
#include "nsTreeDataModel.h"
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// A single item in a hierarchical data model for a tree widget
|
||||||
|
// with columns.
|
||||||
|
//------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "nsHierarchicalDataItem.h"
|
||||||
|
|
||||||
|
class nsTreeItem : public nsHierarchicalDataItem
|
||||||
|
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
nsTreeItem() {}; // Disallow instantiation of abstract class.
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~nsTreeItem() {};
|
||||||
|
|
||||||
|
virtual void GetItemStyle(nsIDeviceContext* dc,
|
||||||
|
nsTreeItemStyleInfo& styleInfo) const = 0;
|
||||||
|
|
||||||
|
virtual void GetTextForColumn(nsTreeColumn* pColumn, nsString& nodeText) const = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsTreeItem_h___ */
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,144 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTreeView_h___
|
||||||
|
#define nsTreeView_h___
|
||||||
|
|
||||||
|
#include "nsITreeView.h"
|
||||||
|
#include "nsTreeDataModel.h"
|
||||||
|
#include "nsTreeItem.h"
|
||||||
|
#include "nsTreeColumn.h"
|
||||||
|
#include "nsTreeControlStripItem.h"
|
||||||
|
#include "nsDataModelWidget.h"
|
||||||
|
|
||||||
|
class nsIImageGroup;
|
||||||
|
class nsIImage;
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
const int cIndentAmount = 19;
|
||||||
|
const int cIconMargin = 2;
|
||||||
|
const int cMinColumnWidth = 30;
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// A tree view consists of several components: a title bar, a control strip,
|
||||||
|
// a column bar, the actual tree contents, and an accompanying scrollbar for the
|
||||||
|
// tree contents.
|
||||||
|
//
|
||||||
|
// The actual tree view knows nothing about the data it is displaying. It queries
|
||||||
|
// a data model for all properties, and then just uses the values it obtains
|
||||||
|
// to display the data. It passes all expand/collapse/deletion/etc. events back
|
||||||
|
// to the data model.
|
||||||
|
|
||||||
|
class nsTreeView : public nsITreeView,
|
||||||
|
public nsDataModelWidget
|
||||||
|
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsTreeView();
|
||||||
|
virtual ~nsTreeView();
|
||||||
|
|
||||||
|
// nsISupports Interface --------------------------------
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
void HandleDataModelEvent(int event, nsHierarchicalDataItem* pItem);
|
||||||
|
|
||||||
|
// Override the widget creation method
|
||||||
|
NS_IMETHOD Create(nsIWidget *aParent,
|
||||||
|
const nsRect &aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
nsIDeviceContext *aContext,
|
||||||
|
nsIAppShell *aAppShell,
|
||||||
|
nsIToolkit *aToolkit,
|
||||||
|
nsWidgetInitData *aInitData);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// These functions are all used in painting.
|
||||||
|
void PaintTitleBar(nsIRenderingContext* drawCtx,
|
||||||
|
nsRect& rect);
|
||||||
|
void PaintControlStrip(nsIRenderingContext* drawCtx,
|
||||||
|
nsRect& rect);
|
||||||
|
|
||||||
|
// These functions are used in painting the column bar.
|
||||||
|
void PaintColumnBar(nsIRenderingContext* drawCtx,
|
||||||
|
nsRect& rect);
|
||||||
|
void PaintColumnHeader(nsIRenderingContext* drawCtx,
|
||||||
|
nsTreeColumn* pColumn,
|
||||||
|
PRUint32& currentPosition,
|
||||||
|
const nsColumnHeaderStyleInfo& styleInfo);
|
||||||
|
void PaintPusherArrow(nsIRenderingContext* drawCtx,
|
||||||
|
PRBool isLeftArrow, int left, int width);
|
||||||
|
|
||||||
|
// These functions are used to paint the lines in the tree.
|
||||||
|
void PaintTreeLines(nsIRenderingContext* drawCtx,
|
||||||
|
nsRect& rect);
|
||||||
|
void PaintTreeLine(nsIRenderingContext* drawCtx, nsTreeItem* pItem, int& yPosition);
|
||||||
|
|
||||||
|
// General function for painting a background image.
|
||||||
|
void PaintBackgroundImage(nsIRenderingContext* drawCtx,
|
||||||
|
nsIImage* bgImage, const nsRect& constraintRect,
|
||||||
|
int xSrcOffset = 0, int ySrcOffset = 0);
|
||||||
|
|
||||||
|
// Helper to parse color strings.
|
||||||
|
void ParseColor(char* colorString, nscolor& colorValue);
|
||||||
|
|
||||||
|
// Column Adjusters/Routines
|
||||||
|
void ResizeColumns(int width);
|
||||||
|
void ShowColumn();
|
||||||
|
void HideColumn();
|
||||||
|
void DragColumnEdge(int xPos);
|
||||||
|
PRBool DownOnColumnEdge(const nsPoint& point);
|
||||||
|
|
||||||
|
// String drawing helper. Crops left, inserts ellipses, and left justifies string.
|
||||||
|
// Assumption is that the font has been set in the
|
||||||
|
// rendering context, so the font metrics can be retrieved and used.
|
||||||
|
void DrawCroppedString(nsIRenderingContext* drawCtx, nsString text,
|
||||||
|
const nsRect& rect);
|
||||||
|
|
||||||
|
NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Data members
|
||||||
|
nsTreeDataModel* mDataModel; // The data source from which everything to draw is obtained.
|
||||||
|
nsIImageGroup* mImageGroup; // Used to make requests for tree images.
|
||||||
|
|
||||||
|
// Cached rects for fast hit testing computation.
|
||||||
|
nsRect mTitleBarRect;
|
||||||
|
nsRect mControlStripRect;
|
||||||
|
nsRect mColumnBarRect;
|
||||||
|
nsRect mTreeRect;
|
||||||
|
|
||||||
|
// This rect is an area that needs to be invalidated once the mouse leaves it.
|
||||||
|
// Used on mouse move events.
|
||||||
|
nsRect mCachedMoveRect; // Is either the control strip or lines in the tree. Only
|
||||||
|
// these items can possibly be invalidated on a mouse move.
|
||||||
|
nsPoint mCachedMovePoint; // Cache the last mouse move.
|
||||||
|
nsPoint mCachedDownPoint; // Cache the mouse down point.
|
||||||
|
|
||||||
|
PRBool mMouseDown; // Whether or not the mouse is pressed.
|
||||||
|
PRBool mMouseDragging; // Whether or not we're dragging something.
|
||||||
|
|
||||||
|
// These members all have to do with dragging the edges of columns to resize them.
|
||||||
|
int mMousedColumnIndex; // The index of the column edge hit on a mouse down.
|
||||||
|
int mLastXPosition; // The last X position of the dragged column edge.
|
||||||
|
PRBool mDraggingColumnEdge; // Whether or not we're dragging a column edge.
|
||||||
|
|
||||||
|
PRBool mDraggingColumnHeader; // Whether or not we're dragging a column header
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsToolbar_h___ */
|
Загрузка…
Ссылка в новой задаче