This commit is contained in:
spider%netscape.com 1998-09-11 01:16:25 +00:00
Родитель 7f46c7bdce
Коммит 2c2a8b1be4
18 изменённых файлов: 689 добавлений и 681 удалений

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

@ -34,8 +34,10 @@
#include "nsCalXMLDTD.h"
#include "nsIXMLParserObject.h"
#include "nsICalTimeContext.h"
#include "nsIXPFCXMLContentSink.h"
class nsCalXMLContentSink : public nsIHTMLContentSink
class nsCalXMLContentSink : public nsIHTMLContentSink,
public nsIXPFCXMLContentSink
{
public:
@ -45,6 +47,9 @@ public:
nsCalXMLContentSink();
virtual ~nsCalXMLContentSink();
NS_IMETHOD Init();
NS_IMETHOD SetViewerContainer(nsIWebViewerContainer * aViewerContainer);
// nsIContentSink
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);

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

@ -32,7 +32,7 @@
#include "nsICalendarShell.h"
#include "nsCalParserCIID.h"
#include "nsxpfcCIID.h"
#include "nsCalendarContainer.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID);
@ -55,6 +55,7 @@ static NS_DEFINE_IID(kCalMultiDayViewCanvasCID, NS_CAL_MULTIDAYVIEWCANVAS_CI
static NS_DEFINE_IID(kCalTimebarCanvasCID, NS_CAL_TIMEBARCANVAS_CID);
static NS_DEFINE_IID(kCalContextcontrollerIID, NS_ICAL_CONTEXT_CONTROLLER_IID);
static NS_DEFINE_IID(kIXPFCXMLContentSinkIID, NS_IXPFC_XML_CONTENT_SINK_IID);
@ -168,6 +169,9 @@ nsresult nsCalXMLContentSink::QueryInterface(const nsIID& aIID, void** aInstance
else if(aIID.Equals(kClassIID)) { //do this class...
*aInstancePtr = (nsCalXMLContentSink*)(this);
}
else if(aIID.Equals(kIXPFCXMLContentSinkIID)) { //do this class...
*aInstancePtr = (nsIXPFCXMLContentSink*)(this);
}
else {
*aInstancePtr=0;
return NS_NOINTERFACE;
@ -177,6 +181,18 @@ nsresult nsCalXMLContentSink::QueryInterface(const nsIID& aIID, void** aInstance
}
NS_IMETHODIMP nsCalXMLContentSink::Init()
{
return NS_OK;
}
NS_IMETHODIMP nsCalXMLContentSink::SetViewerContainer(nsIWebViewerContainer * aViewerContainer)
{
SetWidget(((nsCalendarWidget *)((nsCalendarContainer*)aViewerContainer)->GetDocumentWidget()));
return NS_OK;
}
/*
* this method gets invoked whenever a container type tag
* is encountered.

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

@ -119,7 +119,7 @@ nsresult nsCalParserFactory::CreateInstance(nsISupports *aOuter,
if (mClassID.Equals(kCCalXMLDTD)) {
inst = (nsISupports *)new nsCalXMLDTD();
} else if (mClassID.Equals(kCCalXMLContentSink)) {
inst = (nsISupports *)new nsCalXMLContentSink();
inst = (nsISupports *)(nsIXPFCXMLContentSink *)new nsCalXMLContentSink();
}
if (inst == NULL) {

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

@ -81,11 +81,7 @@ public:
private:
nsIWidget * mWindow;
nsIXPFCCanvas * mRootCanvas ;
nsIURL * mUrl;
nsIStreamListener * mStreamListener;
nsIDTD * mDTD;
nsIParser * mParser;
nsIContentSink * mSink;
public:
nsICalendarShell * mCalendarShell;

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

@ -156,7 +156,7 @@ int RcvData(void * pData,
* the parsing thread to take over. This will help keep the
* list of unparsed buffers to a minimum.
*/
PR_Sleep(PR_INTERVAL_NO_WAIT);
//PR_Sleep(PR_INTERVAL_NO_WAIT);
return iSize > 0 ? 0 : -1;
}
@ -365,10 +365,10 @@ nsresult nsCalendarShell::InitialLoadData()
parseThread = PR_CreateThread(PR_USER_THREAD,
main_CalStreamReader,
pCalStreamReader,
PR_PRIORITY_HIGH,
PR_PRIORITY_NORMAL,
PR_LOCAL_THREAD,
PR_UNJOINABLE_THREAD,
4096);
0);
capiStatus = pCapi->CAPI_SetStreamCallbacks(
mCAPISession, &RcvStream, 0,0,RcvData, pCalStreamReader,0);

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

@ -59,6 +59,7 @@ class nsICalendarShell;
#include "nsCurlParser.h"
#include "nsCalToolkit.h"
#include "nsBoxLayout.h"
#include "nsStreamManager.h"
#include "nsColor.h"
#include "nsFont.h"
@ -100,10 +101,6 @@ class nsICalendarShell;
nsCalendarWidget::nsCalendarWidget()
{
NS_INIT_REFCNT();
mUrl = nsnull;
mParser = nsnull;
mDTD = nsnull;
mSink = nsnull;
mCalendarShell = nsnull;
mWindow = nsnull;
}
@ -117,9 +114,6 @@ nsCalendarWidget::~nsCalendarWidget()
// Release windows and views
NS_IF_RELEASE(mRootCanvas);
NS_IF_RELEASE(mWindow);
NS_IF_RELEASE(mUrl);
NS_IF_RELEASE(mParser);
NS_IF_RELEASE(mSink);
((nsIApplicationShell *)mCalendarShell)->Release();
}
@ -212,679 +206,41 @@ nsresult nsCalendarWidget::GetContainer(nsIContentViewerContainer*& aContainerRe
nsresult nsCalendarWidget::LoadURL(const nsString& aURLSpec, nsIStreamObserver* aListener, nsIPostData * aPostData)
{
/*
* If we can find the file, then use it, else use the HARDCODE.
* We'll need to change the way we deal with this since the file
* could be gotten over the network.
*/
nsresult res ;
nsresult rv = NS_OK;
nsIStreamManager * stream_manager = ((nsCalendarShell *)mCalendarShell)->mShellInstance->GetStreamManager();
PRBool bHardcode = PR_FALSE;
char * pUI = aURLSpec.ToNewCString();
/*
* Create a nsIURL representing the interface ...
*/
if (stream_manager == nsnull)
return NS_OK;
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
nsIStreamListener * aStreamListener;
nsresult res = NS_OK;
nsCurlParser urlParser(pUI);
if (urlParser.IsLocalFile() == PR_TRUE) {
char * pURL = urlParser.LocalFileToURL();
res = NS_NewURL(&mUrl, pURL);
} else {
res = NS_NewURL(&mUrl, pUI);
}
nsIStreamListener * stream_listener;
if (NS_OK != res) {
bHardcode = PR_TRUE;
}
NS_NewCalStreamListener(&stream_listener);
((nsCalStreamListener *)stream_listener)->SetWidget(this);
if (bHardcode == PR_FALSE)
nsIID * iid_dtd = nsnull;
nsIID * iid_sink = nsnull ;
if (aURLSpec.Find(".cal") != -1)
{
if (urlParser.IsLocalFile() == PR_TRUE)
{
PRStatus status = PR_Access(pUI,PR_ACCESS_EXISTS);
static NS_DEFINE_IID(kCCalXMLDTD, NS_ICALXML_DTD_IID);
static NS_DEFINE_IID(kCCalXMLContentSinkCID, NS_CALXMLCONTENTSINK_IID);
if (status == -1)
bHardcode = PR_TRUE;
} else {
char * file = urlParser.ToLocalFile();
PRStatus status = PR_Access(file,PR_ACCESS_EXISTS);
if (status == -1)
bHardcode = PR_TRUE;
//delete file;
}
iid_dtd = (nsIID *) &kCCalXMLDTD;
iid_sink = (nsIID *) &kCCalXMLContentSinkCID;
mRootCanvas->DeleteChildren();
}
if (PR_FALSE == bHardcode)
{
res = stream_manager->LoadURL(((nsCalendarShell*)mCalendarShell)->mDocumentContainer,
aURLSpec,
stream_listener,
aPostData,iid_dtd,iid_sink);
return res;
/*
* Create the Parser
*/
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
rv = nsRepository::CreateInstance(kCParserCID,
nsnull,
kCParserIID,
(void **)&mParser);
if (NS_OK != res) {
return res;
}
/*
* Create the DTD and Sink
*/
// XXX: Really, the parser should figure out the mime type
// of our document and create the correct DTD.
if (PL_strstr(pUI, ".ui") != nsnull)
{
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
static NS_DEFINE_IID(kCCalXPFCXMLDTD, NS_IXPFCXML_DTD_IID);
res = nsRepository::CreateInstance(kCCalXPFCXMLDTD,
nsnull,
kIDTDIID,
(void**) &mDTD);
if (NS_OK != res) {
return res;
}
static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID);
static NS_DEFINE_IID(kCCalXPFCXMLContentSinkCID, NS_XPFCXMLCONTENTSINK_IID);
res = nsRepository::CreateInstance(kCCalXPFCXMLContentSinkCID,
nsnull,
kIContentSinkIID,
(void**) &mSink);
if (NS_OK != res) {
return res;
}
((nsXPFCXMLContentSink *)mSink)->SetViewerContainer(((nsCalendarShell*)mCalendarShell)->mDocumentContainer);
} else {
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
static NS_DEFINE_IID(kCCalXMLDTD, NS_ICALXML_DTD_IID);
res = nsRepository::CreateInstance(kCCalXMLDTD,
nsnull,
kIDTDIID,
(void**) &mDTD);
if (NS_OK != res) {
return res;
}
static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID);
static NS_DEFINE_IID(kCCalXMLContentSinkCID, NS_CALXMLCONTENTSINK_IID);
res = nsRepository::CreateInstance(kCCalXMLContentSinkCID,
nsnull,
kIContentSinkIID,
(void**) &mSink);
if (NS_OK != res) {
return res;
}
((nsCalXMLContentSink *)mSink)->SetWidget(this);
mRootCanvas->DeleteChildren();
}
NS_NewCalStreamListener(&aStreamListener);
/*
* Register the DTD
*/
mParser->RegisterDTD(mDTD);
/*
* Register the Context Sink, Parser, etc...
*/
mParser->SetContentSink(mSink);
mDTD->SetContentSink(mSink);
mDTD->SetParser(mParser);
/*
* XXX: Tell the Stream Listener about us ... this should be done at the
* Content Model Level
*/
((nsCalStreamListener *)aStreamListener)->SetWidget(this);
/*
* Open the URL
*/
res = mUrl->Open(aStreamListener);
/*
* We want to parse when the Stream has data?
*/
mParser->Parse(mUrl);
#if 0
NS_IF_RELEASE(dtd);
NS_IF_RELEASE(sink);
NS_RELEASE(parser);
#endif
} else {
nsIXPFCCanvas * canvas;
nsIXPFCCanvas * headercanvas;
nsIXPFCCanvas * belowheadercanvas;
nsIXPFCCanvas * monthtodoparentcanvas;
nsIXPFCCanvas * timebarscalecanvas;
nsresult res;
static NS_DEFINE_IID(kCCalMultiDayViewCID, NS_CAL_MULTIDAYVIEWCANVAS_CID);
static NS_DEFINE_IID(kCCalTodoComponentCanvasCID, NS_CAL_TODOCOMPONENTCANVAS_CID);
static NS_DEFINE_IID(kCXPFCCanvasCID, NS_XPFC_CANVAS_CID);
static NS_DEFINE_IID(kCCalContextControllerCID, NS_CAL_CONTEXT_CONTROLLER_CID);
static NS_DEFINE_IID(kCCalTimebarContextControllerCID, NS_CAL_TIMEBAR_CONTEXT_CONTROLLER_CID);
static NS_DEFINE_IID(kCCalMonthContextControllerCID, NS_CAL_MONTH_CONTEXT_CONTROLLER_CID);
static NS_DEFINE_IID(kCalTimebarHeadingCID, NS_CAL_TIMEBARHEADING_CID);
static NS_DEFINE_IID(kCalTimebarUserHeadingCID, NS_CAL_TIMEBARUSERHEADING_CID);
static NS_DEFINE_IID(kCalTimebarTimeHeadingCID, NS_CAL_TIMEBARTIMEHEADING_CID);
static NS_DEFINE_IID(kCalTimebarScaleCID, NS_CAL_TIMEBARSCALE_CID);
static NS_DEFINE_IID(kIXPFCCanvasIID, NS_IXPFC_CANVAS_IID);
static NS_DEFINE_IID(kCalContextControllerIID, NS_ICAL_CONTEXT_CONTROLLER_IID);
static NS_DEFINE_IID(kXPFCSubjectIID, NS_IXPFC_SUBJECT_IID);
/******************************************************************************
Let's create a Context that will be shared across the TimebarScale and the
MultiDayView.
*******************************************************************************/
static NS_DEFINE_IID(kCCalTimeContextCID, NS_CAL_TIME_CONTEXT_CID);
static NS_DEFINE_IID(kCCalTimeContextIID, NS_ICAL_TIME_CONTEXT_IID);
static NS_DEFINE_IID(kXPFCObserverIID, NS_IXPFC_OBSERVER_IID);
nsICalTimeContext * context;
nsIXPFCObserver * observer;
res = nsRepository::CreateInstance(kCCalTimeContextCID,
nsnull,
kCCalTimeContextIID,
(void **)&context);
if (NS_OK != res)
return res ;
context->Init();
res = context->QueryInterface(kXPFCObserverIID, (void **)&observer);
nsIXPFCSubject * north_context_subject;
context->QueryInterface(kXPFCSubjectIID, (void **)&north_context_subject);
/*******************************************************************************
First, create 2 canvas as children in the root canvas, with a y box layout.
the top canvas will contain the user header and context controllers, with
a preferred height. The bottom will freefloat and contain everything else.
It will have a minimum so that both start shrinking when the minimum is hit.
*******************************************************************************/
/*
* create canvas to hold header
*/
res = nsRepository::CreateInstance(kCXPFCCanvasCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
canvas->Init();
mRootCanvas->AddChildCanvas(canvas);
canvas->SetPreferredSize(nsSize(50,50));
canvas->SetMaximumSize(nsSize(50,50));
headercanvas = canvas;
/*
* create canvas to hold everything else
*/
res = nsRepository::CreateInstance(kCXPFCCanvasCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
canvas->Init();
mRootCanvas->AddChildCanvas(canvas);
belowheadercanvas = canvas;
// change layout to y box on root canvas
((nsBoxLayout *)(mRootCanvas->GetLayout()))->SetLayoutAlignment(eLayoutAlignment_vertical);
/*******************************************************************************
Add the User Header Bar with context controllers
*******************************************************************************/
/*
Add Context Controller Canvas - West
*/
res = nsRepository::CreateInstance(kCCalTimebarContextControllerCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
headercanvas->AddChildCanvas(canvas);
canvas->SetForegroundColor(FOREGROUND_COLOR);
canvas->SetPreferredSize(nsSize(50,50));
canvas->SetMinimumSize(nsSize(50,50));
canvas->SetMaximumSize(nsSize(50,50));
nsCalTimebarContextController * controller;
res = canvas->QueryInterface(kCalContextControllerIID, (void **)&controller);
nsIXPFCSubject * west_subject;
if (NS_OK == res) {
controller->Init();
controller->SetOrientation(nsContextControllerOrientation_west);
controller->SetPeriodFormat(nsCalPeriodFormat_kDay);
controller->GetDuration()->SetDay(-1);
res = controller->QueryInterface(kXPFCSubjectIID, (void **)&west_subject);
NS_RELEASE(controller);
}
/*
Add Timebar Heading Canvas
*/
nsRepository::CreateInstance(kCalTimebarUserHeadingCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
headercanvas->AddChildCanvas(canvas);
canvas->SetMinimumSize(nsSize(50,50));
/*
Add Context Controller Canvas - East
*/
nsRepository::CreateInstance(kCCalTimebarContextControllerCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
headercanvas->AddChildCanvas(canvas);
canvas->SetForegroundColor(FOREGROUND_COLOR);
canvas->SetPreferredSize(nsSize(50,50));
canvas->SetMinimumSize(nsSize(50,50));
canvas->SetMaximumSize(nsSize(50,50));
res = canvas->QueryInterface(kCalContextControllerIID, (void **)&controller);
nsIXPFCSubject * east_subject;
if (NS_OK == res) {
controller->Init();
controller->SetOrientation(nsContextControllerOrientation_east);
controller->SetPeriodFormat(nsCalPeriodFormat_kDay);
controller->GetDuration()->SetDay(1);
res = controller->QueryInterface(kXPFCSubjectIID, (void **)&east_subject);
NS_RELEASE(controller);
}
/*******************************************************************************
Here we add the blank container for timescale, multi-day view,
blank container for monthview/todo As a child of the belowheadercanvas
*******************************************************************************/
/*
Add a canvas for Timebar Scale Canvas
*/
nsRepository::CreateInstance(kCXPFCCanvasCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
canvas->Init();
belowheadercanvas->AddChildCanvas(canvas);
canvas->SetPreferredSize(nsSize(50,50));
canvas->SetMinimumSize(nsSize(50,50));
//canvas->SetMaximumSize(nsSize(50,50));
timebarscalecanvas = canvas;
// change layout to y box on this canvas
((nsBoxLayout *)(timebarscalecanvas->GetLayout()))->SetLayoutAlignment(eLayoutAlignment_vertical);
/*******************************************************************************
Add MultiDayView Canvas with a Command canvas if Debug mode is set
*******************************************************************************/
/*
* Blank canvas for holding multiday and command/status container
*/
nsRepository::CreateInstance(kCXPFCCanvasCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
canvas->Init();
belowheadercanvas->AddChildCanvas(canvas);
canvas->SetMinimumSize(nsSize(50,50));
// change layout to y box
((nsBoxLayout *)(canvas->GetLayout()))->SetLayoutAlignment(eLayoutAlignment_vertical);
nsIXPFCCanvas * multiday_holder_canvas = canvas;
/*
* The true multiday canvas
*/
nsRepository::CreateInstance(kCCalMultiDayViewCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
((nsCalMultiDayViewCanvas*)canvas)->SetShowStatus(PR_FALSE);
canvas->Init();
multiday_holder_canvas->AddChildCanvas(canvas);
canvas->SetMinimumSize(nsSize(50,50));
((nsCalTimebarCanvas *)canvas)->SetTimeContext(context);
nsIXPFCObserver * observer_multiday;
canvas->QueryInterface(kXPFCObserverIID, (void **)&observer_multiday);
/*
* A Command Canvas
*/
#ifdef DEBUG
static NS_DEFINE_IID(kCCalBottomCanvasCID, NS_CAL_COMMANDCANVAS_CID);
#else
static NS_DEFINE_IID(kCCalBottomCanvasCID, NS_CAL_STATUSCANVAS_CID);
#endif
nsRepository::CreateInstance(kCCalBottomCanvasCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
multiday_holder_canvas->AddChildCanvas(canvas);
canvas->Init();
canvas->SetPreferredSize(nsSize(25,25));
canvas->SetMinimumSize(nsSize(25,25));
canvas->SetMaximumSize(nsSize(25,25));
/*
Add canvas that is blank
*/
nsRepository::CreateInstance(kCXPFCCanvasCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
canvas->Init();
belowheadercanvas->AddChildCanvas(canvas);
canvas->SetPreferredSize(nsSize(HARDCODE_SPACE>>1,HARDCODE_SPACE>>1));
canvas->SetMinimumSize(nsSize(HARDCODE_SPACE>>1,HARDCODE_SPACE>>1));
canvas->SetMaximumSize(nsSize(HARDCODE_SPACE>>1,HARDCODE_SPACE>>1));
// change layout to y box
((nsBoxLayout *)(canvas->GetLayout()))->SetLayoutAlignment(eLayoutAlignment_vertical);
monthtodoparentcanvas = canvas ;
/*******************************************************************************
Here we add the Timescale and associated controllers
*******************************************************************************/
/*
Add Context Controller Canvas - North
*/
res = nsRepository::CreateInstance(kCCalTimebarContextControllerCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
timebarscalecanvas->AddChildCanvas(canvas);
canvas->SetForegroundColor(FOREGROUND_COLOR);
canvas->SetPreferredSize(nsSize(25,25));
res = canvas->QueryInterface(kCalContextControllerIID, (void **)&controller);
nsIXPFCSubject * north_subject;
if (NS_OK == res) {
controller->Init();
controller->SetOrientation(nsContextControllerOrientation_north);
controller->SetPeriodFormat(nsCalPeriodFormat_kHour);
controller->GetDuration()->SetHour(-1);
res = controller->QueryInterface(kXPFCSubjectIID, (void **)&north_subject);
NS_RELEASE(controller);
}
/*
Add Timebar Scale Canvas
*/
nsRepository::CreateInstance(kCalTimebarScaleCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
canvas->Init();
timebarscalecanvas->AddChildCanvas(canvas);
((nsCalTimebarCanvas *)canvas)->SetTimeContext(context);
nsIXPFCObserver * observer_timescale;
canvas->QueryInterface(kXPFCObserverIID, (void **)&observer_timescale);
/*
Add Context Controller Canvas - South
*/
res = nsRepository::CreateInstance(kCCalTimebarContextControllerCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
timebarscalecanvas->AddChildCanvas(canvas);
canvas->SetForegroundColor(FOREGROUND_COLOR);
canvas->SetPreferredSize(nsSize(25,25));
res = canvas->QueryInterface(kCalContextControllerIID, (void **)&controller);
nsIXPFCSubject * south_subject;
if (NS_OK == res) {
controller->Init();
controller->SetOrientation(nsContextControllerOrientation_south);
controller->SetPeriodFormat(nsCalPeriodFormat_kHour);
controller->GetDuration()->SetHour(1);
res = controller->QueryInterface(kXPFCSubjectIID, (void **)&south_subject);
NS_RELEASE(controller);
}
nsICalContextController * south_controller = controller;
/*******************************************************************************
Here we add the MiniCal and TodoView as a child of the above canvas
*******************************************************************************/
/*
Add MiniCal Canvas
*/
nsRepository::CreateInstance(kCCalMonthContextControllerCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
canvas->Init();
monthtodoparentcanvas->AddChildCanvas(canvas);
canvas->SetPreferredSize(nsSize(HARDCODE_SPACE,HARDCODE_SPACE));
canvas->SetMinimumSize(nsSize(HARDCODE_SPACE,HARDCODE_SPACE));
canvas->SetMaximumSize(nsSize(HARDCODE_SPACE,HARDCODE_SPACE));
res = canvas->QueryInterface(kCalContextControllerIID, (void **)&controller);
nsIXPFCSubject * month_subject;
nsIXPFCObserver * observer_month_controller;
if (NS_OK == res) {
controller->Init();
controller->SetOrientation(nsContextControllerOrientation_north);
res = controller->QueryInterface(kXPFCSubjectIID, (void **)&month_subject);
res = controller->QueryInterface(kXPFCObserverIID, (void **)&observer_month_controller);
NS_RELEASE(controller);
}
/*
Add Todo Canvas
*/
nsRepository::CreateInstance(kCCalTodoComponentCanvasCID,
nsnull,
kIXPFCCanvasIID,
(void **)&canvas);
if (NS_OK != res)
return res ;
monthtodoparentcanvas->AddChildCanvas(canvas);
canvas->Init();
/*******************************************************************************
Setup Observers
*******************************************************************************/
// ContextController is SUBJECT, Context is Observer
mCalendarShell->GetObserverManager()->Register(north_subject, observer);
mCalendarShell->GetObserverManager()->Register(south_subject, observer);
mCalendarShell->GetObserverManager()->Register(east_subject, observer);
mCalendarShell->GetObserverManager()->Register(west_subject, observer);
mCalendarShell->GetObserverManager()->Register(month_subject, observer);
// Context is subject, Canvas is observer
mCalendarShell->GetObserverManager()->Register(north_context_subject, observer_timescale);
mCalendarShell->GetObserverManager()->Register(north_context_subject, observer_multiday);
// Context is subject, controller is observer
mCalendarShell->GetObserverManager()->Register(north_context_subject, observer_month_controller);
NS_RELEASE(north_subject);
NS_RELEASE(south_subject);
NS_RELEASE(east_subject);
NS_RELEASE(west_subject);
/*******************************************************************************
Layout the children
*******************************************************************************/
mRootCanvas->Layout();
#if defined(DEBUG) && defined(XP_PC)
// mRootCanvas->DumpCanvas(stdout,0);
#endif
}
delete pUI;
return rv;
}
@ -918,9 +274,14 @@ nsIStreamListener * nsCalendarWidget::GetParserStreamInterface()
{
NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
nsIStreamManager * stream_manager = ((nsCalendarShell *)mCalendarShell)->mShellInstance->GetStreamManager();
if (stream_manager == nsnull)
return nsnull;
nsIStreamListener * aStreamListener ;
nsresult res = mParser->QueryInterface(kIStreamListenerIID, (void **)&aStreamListener);
nsresult res = ((nsStreamManager *)stream_manager)->mParser->QueryInterface(kIStreamListenerIID, (void **)&aStreamListener);
if (NS_OK != res)
return (nsnull);

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

@ -115,7 +115,7 @@ nsresult nsxpfcFactory::CreateInstance(nsISupports *aOuter,
} else if (mClassID.Equals(kCXPFCDTD)) {
inst = (nsISupports *)new nsXPFCXMLDTD();
} else if (mClassID.Equals(kCXPFCContentSink)) {
inst = (nsISupports *)new nsXPFCXMLContentSink();
inst = (nsISupports *)(nsIXPFCXMLContentSink*)new nsXPFCXMLContentSink();
} else if (mClassID.Equals(kCVector)) {
inst = (nsISupports *)new nsVector();
} else if (mClassID.Equals(kCVectorIterator)) {

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

@ -31,8 +31,10 @@
#include "nsHTMLTokens.h"
#include "nsXPFCXMLDTD.h"
#include "nsIXMLParserObject.h"
#include "nsIXPFCXMLContentSink.h"
class nsXPFCXMLContentSink : public nsIHTMLContentSink
class nsXPFCXMLContentSink : public nsIHTMLContentSink,
public nsIXPFCXMLContentSink
{
public:
@ -42,6 +44,9 @@ public:
nsXPFCXMLContentSink();
virtual ~nsXPFCXMLContentSink();
NS_IMETHOD Init();
NS_IMETHOD SetViewerContainer(nsIWebViewerContainer * aViewerContainer);
// nsIContentSink
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
@ -67,8 +72,6 @@ public:
NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
NS_IMETHOD CloseFrameset(const nsIParserNode& aNode);
NS_IMETHOD SetViewerContainer(nsIWebViewerContainer * aViewerContainer);
private:
NS_IMETHOD CIDFromTag(eXPFCXMLTags tag, nsCID &aClass);
NS_IMETHOD ConsumeAttributes(const nsIParserNode& aNode, nsIXMLParserObject& aObject);

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

@ -14,6 +14,7 @@ EXPORTS = \
nsIXMLParserObject.h \
nsIMenuManager.h \
nsIToolbarManager.h \
nsIXPFCXMLContentSink.h \
$(NULL)
PRIVATE_EXPORTS = \

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

@ -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 nsIXPFCXMLContentSink_h___
#define nsIXPFCXMLContentSink_h___
#include "nsISupports.h"
#include "nsIWebViewerContainer.h"
//c47f83e0-4910-11d2-924a-00805f8a7ab6
#define NS_IXPFC_XML_CONTENT_SINK_IID \
{ 0xc47f83e0, 0x4910, 0x11d2, \
{ 0x92, 0x4a, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6 } }
class nsIXPFCXMLContentSink : public nsISupports
{
public:
NS_IMETHOD Init() = 0 ;
NS_IMETHOD SetViewerContainer(nsIWebViewerContainer * aViewerContainer) = 0;
};
#endif /* nsIXPFCXMLContentSink_h___ */

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

@ -53,6 +53,7 @@ static NS_DEFINE_IID(kCTabWidgetCID, NS_TABWIDGET_CID);
static NS_DEFINE_IID(kCXPFCButtonCID, NS_XPFC_BUTTON_CID);
static NS_DEFINE_IID(kCXPFCTabWidgetCID, NS_XPFC_TABWIDGET_CID);
static NS_DEFINE_IID(kCXPFCTextWidgetCID, NS_XPFC_TEXTWIDGET_CID);
static NS_DEFINE_IID(kIXPFCXMLContentSinkIID, NS_IXPFC_XML_CONTENT_SINK_IID);
#define XPFC_PARSING_STATE_UNKNOWN 0
#define XPFC_PARSING_STATE_TOOLBAR 1
@ -158,6 +159,9 @@ nsresult nsXPFCXMLContentSink::QueryInterface(const nsIID& aIID, void** aInstanc
else if(aIID.Equals(kClassIID)) { //do this class...
*aInstancePtr = (nsXPFCXMLContentSink*)(this);
}
else if(aIID.Equals(kIXPFCXMLContentSinkIID)) { //do this class...
*aInstancePtr = (nsIXPFCXMLContentSink*)(this);
}
else {
*aInstancePtr=0;
return NS_NOINTERFACE;
@ -166,6 +170,11 @@ nsresult nsXPFCXMLContentSink::QueryInterface(const nsIID& aIID, void** aInstanc
return NS_OK;
}
NS_IMETHODIMP nsXPFCXMLContentSink::Init()
{
return NS_OK;
}
/*
* this method gets invoked whenever a container type tag

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

@ -42,6 +42,21 @@ public:
*/
NS_IMETHOD Init();
NS_IMETHOD LoadURL(nsIWebViewerContainer * aWebViewerContainer,
const nsString& aURLSpec,
nsIStreamListener* aListener,
nsIPostData * aPostData,
nsIID *aDTDIID = nsnull,
nsIID *aSinkIID = nsnull);
private:
nsIURL * mUrl;
nsIDTD * mDTD;
nsIContentSink * mSink;
public:
nsIParser * mParser;
};

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

@ -22,6 +22,9 @@
#include "nscore.h"
#include "nsxpfc.h"
#include "nsISupports.h"
#include "nsIWebViewerContainer.h"
#include "nsIURL.h"
#include "nsIStreamListener.h"
// 5f680140-360f-11d2-9248-00805f8a7ab6
#define NS_ISTREAM_MANAGER_IID \
@ -39,6 +42,13 @@ public:
*/
NS_IMETHOD Init() = 0;
NS_IMETHOD LoadURL(nsIWebViewerContainer * aWebViewerContainer,
const nsString& aURLSpec,
nsIStreamListener* aListener,
nsIPostData * aPostData,
nsIID *aDTDIID = nsnull,
nsIID *aSinkIID = nsnull) = 0;
};

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

@ -22,6 +22,11 @@
#include "nsISupports.h"
#include "nsStreamManager.h"
#include "nsxpfcCIID.h"
#include "nsIContentSink.h"
#include "nsUrlParser.h"
#include "nspr.h"
#include "nsParserCIID.h"
#include "nsXPFCXMLContentSink.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
@ -30,10 +35,17 @@ static NS_DEFINE_IID(kCStreamManager, NS_STREAM_MANAGER_CID);
nsStreamManager::nsStreamManager()
{
NS_INIT_REFCNT();
mUrl = nsnull;
mParser = nsnull;
mDTD = nsnull;
mSink = nsnull;
}
nsStreamManager::~nsStreamManager()
{
NS_IF_RELEASE(mUrl);
NS_IF_RELEASE(mParser);
NS_IF_RELEASE(mSink);
}
NS_DEFINE_IID(kIStreamManagerIID, NS_ISTREAM_MANAGER_IID);
@ -44,3 +56,150 @@ nsresult nsStreamManager::Init()
return NS_OK;
}
nsresult nsStreamManager::LoadURL(nsIWebViewerContainer * aWebViewerContainer,
const nsString& aURLSpec,
nsIStreamListener* aListener,
nsIPostData * aPostData,
nsIID *aDTDIID,
nsIID *aSinkIID)
{
/*
* If we can find the file, then use it, else use the HARDCODE.
* We'll need to change the way we deal with this since the file
* could be gotten over the network.
*/
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID);
static NS_DEFINE_IID(kCCalXPFCXMLDTD, NS_IXPFCXML_DTD_IID);
static NS_DEFINE_IID(kCCalXPFCXMLContentSinkCID, NS_XPFCXMLCONTENTSINK_IID);
nsIID * iid_dtd = aDTDIID;
nsIID * iid_sink = aSinkIID;
if (iid_dtd == nsnull)
iid_dtd = (nsIID*)&kCCalXPFCXMLDTD;
if (iid_sink == nsnull)
iid_sink = (nsIID*)&kCCalXPFCXMLContentSinkCID;
nsresult rv = NS_OK;
char * pUI = aURLSpec.ToNewCString();
/*
* Create a nsIURL representing the interface ...
*/
nsresult res = NS_OK;
nsUrlParser urlParser(pUI);
if (urlParser.IsLocalFile() == PR_TRUE) {
char * pURL = urlParser.LocalFileToURL();
res = NS_NewURL(&mUrl, pURL);
} else {
res = NS_NewURL(&mUrl, pUI);
}
if (urlParser.IsLocalFile() == PR_TRUE)
{
PRStatus status = PR_Access(pUI,PR_ACCESS_EXISTS);
} else {
char * file = urlParser.ToLocalFile();
PRStatus status = PR_Access(file,PR_ACCESS_EXISTS);
}
/*
* Create the Parser
*/
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
rv = nsRepository::CreateInstance(kCParserCID,
nsnull,
kCParserIID,
(void **)&mParser);
if (NS_OK != res) {
return res;
}
/*
* Create the DTD and Sink
*/
res = nsRepository::CreateInstance(*iid_dtd,
nsnull,
kIDTDIID,
(void**) &mDTD);
if (NS_OK != res) {
return res;
}
res = nsRepository::CreateInstance(*iid_sink,
nsnull,
kIContentSinkIID,
(void**) &mSink);
if (NS_OK != res) {
return res;
}
nsIXPFCXMLContentSink * sink ;
static NS_DEFINE_IID(kIXPFCXMLContentSinkIID, NS_IXPFC_XML_CONTENT_SINK_IID);
res = mSink->QueryInterface(kIXPFCXMLContentSinkIID,(void**)&sink);
if (NS_OK == res)
{
sink->SetViewerContainer(aWebViewerContainer);
NS_RELEASE(sink);
}
/*
* Register the DTD
*/
mParser->RegisterDTD(mDTD);
/*
* Register the Context Sink, Parser, etc...
*/
mParser->SetContentSink(mSink);
mDTD->SetContentSink(mSink);
mDTD->SetParser(mParser);
/*
* Open the URL
*/
res = mUrl->Open(aListener);
/*
* We want to parse when the Stream has data?
*/
mParser->Parse(mUrl);
delete pUI;
return rv;
}

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

@ -17,6 +17,7 @@ PRIVATE_EXPORTS = \
nsVector.h \
nsStack.h \
nsxpfcutil.h \
nsUrlParser.h \
$(NULL)
MODULE = xpfc

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

@ -0,0 +1,61 @@
/* -*- 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.
*/
/**
* This class manages a string in one of the following forms:
*
* protocol://host.domain[:port]/user[:extra]
* mailto:user@host.domain
*
* It provides quick access to its component parts.
* Expected protocols are: CAPI, IRIP, MAILTO
*
* This code probably exists somewhere else.
*
* sman
*
* Modification: Code supports converting from "file:" and "resource:"
* to platform specific file handle.
*
*/
#include "nscore.h"
class nsUrlParser
{
private:
nsString m_sURL;
public:
nsUrlParser(char* psCurl);
nsUrlParser(nsString& sCurl);
virtual ~nsUrlParser();
NS_METHOD_(char *) ToLocalFile();
NS_METHOD_(PRBool) IsLocalFile();
NS_IMETHOD_(char *) LocalFileToURL();
private:
NS_METHOD_(char *) ResourceToFile();
};

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

@ -21,6 +21,7 @@ CPPSRCS = \
nsVectorIterator.cpp \
nsVector.cpp \
nsStack.cpp \
nsUrlParser.cpp \
$(NULL)
REQUIRES = xpcom raptor

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

@ -0,0 +1,330 @@
/* -*- 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.
*/
#ifdef XP_PC
#include "windows.h"
#endif
#include "nscore.h"
#include "nsString.h"
#include "nsUrlParser.h"
#include "nspr.h"
#include "plstr.h"
nsUrlParser::nsUrlParser(nsString& sCurl)
{
m_sURL = sCurl;
}
nsUrlParser::nsUrlParser(char* psCurl)
{
m_sURL = psCurl;
}
nsUrlParser::~nsUrlParser()
{
}
/*
* Assumes full path passed in. This is to differentiate from
* file: URL's
*/
PRBool nsUrlParser::IsLocalFile()
{
PRBool bLocal = PR_FALSE;
char * pszFile = (char *) m_sURL.ToNewCString();
if (pszFile != nsnull)
{
/// XP_MAC?
#ifdef XP_UNIX
if (PL_strlen(pszFile) > 0)
{
if (pszFile[0] == '/')
bLocal = PR_TRUE;
}
#else
if (PL_strlen(pszFile) > 2)
{
if ((pszFile[1] == ':') && (pszFile[2] == '\\'))
bLocal = PR_TRUE;
}
#endif
delete pszFile;
}
return bLocal;
}
/*
* this method converts a "file://" or "resource://" URL
* to a platform specific file handle. It is the caller's
* responsibility to free ther returned string using
* PR_Free().
*
* This code was lifted partly from Live3D and Netlib (nsURL.cpp).
* May the Lord above have mercy on my soul.....
*
*/
char * nsUrlParser::ToLocalFile()
{
char * pszFile = nsnull;
char * pszURL = (char *) m_sURL.ToNewCString();
/*
* Check to see it is a local file already
*/
if (IsLocalFile() == PR_TRUE)
return pszURL;
if (PL_strncasecmp(pszURL, "resource://",11) == 0)
{
pszFile = ResourceToFile();
} else {
pszFile = (char *)PR_Malloc(PL_strlen(pszURL));
pszFile[0] = '\0' ;
if (PL_strncasecmp(pszURL, "file://", 7) == 0)
{
char *pSrc = pszURL + 7 ;
if (PL_strncasecmp(pSrc, "//", 2) == 0) // file:////<hostname>
{
PL_strcpy(pszFile, pSrc) ;
}
else
{
if (PL_strncasecmp(pSrc, "localhost/", 10) == 0) // file://localhost/
{
pSrc += 10 ; // Go past the '/' after "localhost"
}
else
{
if (*pSrc == '/') // file:///
pSrc++ ;
}
if (*(pSrc+1) == '|') // We got a drive letter
{
PL_strcpy(pszFile, pSrc) ;
pszFile[1] = ':' ;
}
else
{
#ifdef XP_UNIX
pszFile[0] = '/' ;
PL_strcpy(pszFile+1, pSrc) ;
#else
pszFile[0] = 'C' ;
pszFile[1] = ':' ;
pszFile[2] = '/' ;
PL_strcpy(pszFile+3, pSrc) ;
#endif
}
}
#ifndef XP_UNIX
char *pDest = pszFile ;
while(*pDest != '\0') // translate '/' to '\' -> PC stuff
{
if (*pDest == '/')
*pDest = '\\' ;
pDest++ ;
}
#endif
}
}
delete pszURL;
return pszFile;
}
char * nsUrlParser::ResourceToFile()
{
char * aResourceFileName = (char *) m_sURL.ToNewCString();
// XXX For now, resources are not in jar files
// Find base path name to the resource file
char* resourceBase;
#ifdef XP_PC
char * cp;
// XXX For now, all resources are relative to the .exe file
resourceBase = (char *)PR_Malloc(_MAX_PATH);;
DWORD mfnLen = GetModuleFileName(NULL, resourceBase, _MAX_PATH);
// Truncate the executable name from the rest of the path...
cp = strrchr(resourceBase, '\\');
if (nsnull != cp) {
*cp = '\0';
}
// Change the first ':' into a '|'
cp = PL_strchr(resourceBase, ':');
if (nsnull != cp) {
*cp = '|';
}
#endif
#ifdef XP_UNIX
// XXX For now, all resources are relative to the current working directory
FILE *pp;
#define MAXPATHLEN 2000
resourceBase = (char *)PR_Malloc(MAXPATHLEN);;
if (!(pp = popen("pwd", "r"))) {
printf("RESOURCE protocol error in nsURL::mangeResourceIntoFileURL 1\n");
return(nsnull);
}
else {
if (fgets(resourceBase, MAXPATHLEN, pp)) {
printf("[%s] %d\n", resourceBase, PL_strlen(resourceBase));
resourceBase[PL_strlen(resourceBase)-1] = 0;
}
else {
printf("RESOURCE protocol error in nsURL::mangeResourceIntoFileURL 2\n");
return(nsnull);
}
}
printf("RESOURCE name %s\n", resourceBase);
#endif
// Join base path to resource name
if (aResourceFileName[0] == '/') {
aResourceFileName++;
}
PRInt32 baseLen = PL_strlen(resourceBase);
PRInt32 resLen = PL_strlen(aResourceFileName);
PRInt32 totalLen = 8 + baseLen + 1 + resLen + 1;
char* fileName = (char *)PR_Malloc(totalLen);
PR_snprintf(fileName, totalLen, "file:///%s/%s", resourceBase, aResourceFileName+11);
#ifdef XP_PC
// Change any backslashes into foreward slashes...
while ((cp = PL_strchr(fileName, '\\')) != 0) {
*cp = '/';
cp++;
}
#endif
PR_Free(resourceBase);
nsString oldString = m_sURL ;
m_sURL = fileName ;
char *localFile = ToLocalFile();
m_sURL = oldString;
PR_Free(fileName);
delete aResourceFileName;
return localFile;
}
#define MAX_URL 1024
char * nsUrlParser::LocalFileToURL()
{
char * pszFile = (char *) m_sURL.ToNewCString();
char * pszURL = (char *)PR_Malloc(MAX_URL);
pszURL[0] = '\0';
#ifdef XP_PC
if (IsLocalFile() == PR_TRUE)
{
char szDrive[5], szDir[255], szFile[10], szExt[5] ;
PL_strcpy(pszURL, "file:///") ;
_splitpath(pszFile, szDrive, szDir, szFile, szExt) ;
if (szDrive[0] != '\0')
{
PL_strcat(pszURL, szDrive) ;
pszURL[PL_strlen(pszURL)-1] = '|' ;
}
char *pDest = szDir ;
while(*pDest != '\0') // translate '\' to '/' -> PC stuff
{
if (*pDest == '\\')
*pDest = '/' ;
pDest++ ;
}
PL_strcat(pszURL, szDir) ;
PL_strcat(pszURL, szFile) ;
PL_strcat(pszURL, szExt) ;
}
else
{
// ***************************************************************
// Need to handle file spec of "\\host\c\vrml\bobo.wrl"
// and convert it to "file:////host/c/vrml/bobo.wrl"
if ((pszFile[0] == '\\') && (pszFile[1] == '\\'))
{
PL_strcpy(pszURL, "file://") ;
PL_strcat(pszURL, pszFile) ;
char *pDest = pszURL ;
while(*pDest != '\0') // translate '\' to '/' -> PC stuff
{
if (*pDest == '\\')
*pDest = '/' ;
pDest++ ;
}
}
else
{
// TODO: Should check that pszFile is a valid HTTP here!
PL_strcpy(pszURL, pszFile) ;
}
}
#endif
delete pszFile;
return pszURL;
}