Free the lizard

git-svn-id: svn://10.0.0.236/trunk@10 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ltabb
1998-03-28 02:44:41 +00:00
parent 53f8de8141
commit 8ed5afe62c
5423 changed files with 1772023 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#!gmake
#
# 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.
DEPTH = ../..
DIRS = src public
include $(DEPTH)/config/rules.mk

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,26 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
In order for this module to work, PW_Resources.cnst must be the part of the main binary,
otherwise, we'll be unable to find the resources.
The correct way to find the resources would be to store our RF number in the binary, but
I did not figure out how to do this painlessly (without figuring our RF number inside
__initialize).
atotic

View File

@@ -0,0 +1,21 @@
#!gmake
#
# 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.
DEPTH=..\..
DIRS=src public
!include $(MOZ_SRC)\ns\config\rules.mak

View File

@@ -0,0 +1,24 @@
#
# 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.
#
DEPTH = ../../..
MODULE = progress
EXPORTS = pw_public.h
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,26 @@
#!gmake
#
# 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.
IGNORE_MANIFEST=1
#
MODULE=progress
DEPTH=..\..\..
EXPORTS=pw_public.h
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,127 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* pw_public.h
* public progress module interface
* Progress module has two main parts:
* progress window
* you can create a standard progress window
* that monitors the progress of a download
* progress context
* you can create an MWContext suitable for downloading
* with NET_GetURL
* progress context can be 'attached' to progress window and
* will display standard progress messages during download while
* it is attached
*/
#ifndef _PW_PUBLIC_H_
#define _PW_PUBLIC_H_
#include "structs.h"
XP_BEGIN_PROTOS
/***************************************************************
* PW window interface
***************************************************************/
typedef void * pw_ptr;
typedef enum PW_WindowType {
pwApplicationModal,
pwStandard
};
typedef void(*PW_CancelCallback) (void * closure);
/* Creates the progress window */
/* The window is invisible until you call PW_Show */
pw_ptr PW_Create( MWContext * parent, /* Parent window, can be NULL */
PW_WindowType type /* What kind of window ? Modality, etc */
);
/* Setup */
void PW_SetCancelCallback(pw_ptr pw,
PW_CancelCallback cancelcb, /* Callback function for cancel */
void * cancelClosure); /* closure for cancel callback */
/*
* Window visibility
*/
/* Show the window */
/* brings the window to front if already visible */
void PW_Show(pw_ptr pw);
/* Hide the window. Does NOT destroy it */
void PW_Hide(pw_ptr pw);
/* Destroys the window */
void PW_Destroy(pw_ptr pw);
/**
* Text progress display
* all char * arguments can be NULL to erase
**/
void PW_SetWindowTitle(pw_ptr pw, const char * title);
void PW_SetLine1(pw_ptr pw, const char * text);
void PW_SetLine2(pw_ptr pw, const char * text);
/* aka SetLine3, named SetProgressText because this is where the
* usual "23K of 1235K (5 seconds remaining)" line goes
*/
void PW_SetProgressText(pw_ptr pw, const char * text);
/**
* Progress bar display
**/
/* if !(maximum > minimum) displays rotating pylon */
void PW_SetProgressRange(pw_ptr pw, int32 minimum, int32 maximum);
void PW_SetProgressValue(pw_ptr pw, int32 value);
/***************************************************************
* PW context interface
***************************************************************/
/* Purpose: create a downloading context anyone can use and destroy */
/* You can associate it with progress window to automatically display */
/* progress window text */
MWContext * PW_CreateProgressContext();
void PW_DestroyProgressContext(MWContext * context);
/* Associates MWContextProgressModule context with a downloading window */
/* If done so, the xp_thermo progress stuff will be displayed in the */
/* ProgressLine */
/* Make sure that you disassociate window from the context when window is */
/* destroyed by passing NULL as pw_ptr */
void PW_AssociateWindowWithContext(MWContext * context, pw_ptr pw);
XP_END_PROTOS
#endif

View File

@@ -0,0 +1,28 @@
#
# 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.
#
DEPTH = ../../..
MODULE = progress
LIBRARY_NAME = prgrss
REQUIRES = progress nspr dbm img layer util
# all code is platform specific right now
CPPSRCS = pw_win.cpp pw_unix.cpp pwcommon.cpp
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,53 @@
#!gmake
#
# 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.
IGNORE_MANIFEST=1
#
DEPTH= ..\..\..
LIBRARY_SUFFIX=$(MOZ_BITS)
MAKE_OBJ_TYPE=EXE
MODULE=progress
REQUIRES=progress nspr dbm img layer util
LIBRARY_NAME=prgrss
DEPTH=..\..\..
CPPSRCS=pw_win.cpp pw_unix.cpp pwcommon.cpp
CPP_OBJS=.\$(OBJDIR)\pw_win.obj .\$(OBJDIR)\pw_unix.obj \
.\$(OBJDIR)\pwcommon.obj
!if "$(MOZ_BITS)" != "16"
LINCS=-I$(XPDIST)\public\progress -I$(XPDIST)\public\nspr \
-I$(XPDIST)\public\dbm -I$(XPDIST)\public\img \
-I$(XPDIST)\public\layer -I$(XPDIST)\public\util
!endif
include <$(DEPTH)\config\rules.mak>
# XXX this should not be required, but mantomake doesnt grok J?I yet
# also, -I..\public should be -I$(PUBLIC)\progress
LINCS= $(LINCS) \
-I$(DEPTH)/cmd/winfe \
-I..\public
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
$(RM) $(DIST)\lib\$(LIBRARY)

View File

@@ -0,0 +1,291 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* pw_mac.cpp
* author: atotic
* Mac implementation of progress interface
*/
#define OLDROUTINENAMES 0 // Why is this here?
#include <PP_ClassHeaders.cp> // pchen: put <PP_ClassHeaders.cp> ahead of pw_public.h
// to avoid TRUE and FALSE redefine error
#include "pw_public.h"
#include <TextEdit.h>
#include "uapp.h"
#include "PP_Messages.h"
#include "CPatternProgressBar.h"
#include "UDesktop.h"
#define PW_WINDOW_ID 5102
class CProgressMac: public LListener {
public:
LWindow * fWindow;
LCaption * fLine1, * fLine2, * fLine3;
CPatternProgressBar * fProgress;
PW_CancelCallback fCancelcb;
void * fCancelClosure;
// Constructors
CProgressMac(PW_WindowType type);
virtual ~CProgressMac();
// PW interface
void SetCancelCallback(PW_CancelCallback cancelcb, /* Callback function for cancel */
void * cancelClosure);
void Show();
void Hide();
void SetWindowTitle(const char * title);
void SetLine1(const char * text);
void SetLine2(const char * text);
void SetProgressText(const char * text);
void SetProgressRange(int32 minimum, int32 maximum);
void SetProgressValue(int32 value);
void ListenToMessage( MessageT inMessage, void* ioParam );
};
CProgressMac::CProgressMac(PW_WindowType type)
{
fCancelcb = NULL;
fCancelClosure = NULL;
// Create the window
// Our default resource stores an application modal, need to change the resource
// before loading it in
SWINDResourceH theWIND = NULL;
if ( type == pwStandard )
{
theWIND = (SWINDResourceH) ::GetResource('WIND', PW_WINDOW_ID);
if ( theWIND )
{
HLock( (Handle)theWIND );
(*theWIND)->procID = 4;
}
}
LCommander::SetDefaultCommander(CFrontApp::GetApplication());
fWindow = LWindow::CreateWindow( PW_WINDOW_ID, NULL );
ThrowIfNil_(fWindow);
if ( type == pwStandard )
{
(*theWIND)->procID = 5; // revert
HUnlock( (Handle)theWIND );
}
fLine1 = (LCaption*)fWindow->FindPaneByID('LIN1');
fLine2 = (LCaption*)fWindow->FindPaneByID('LIN2');
fLine3 = (LCaption*)fWindow->FindPaneByID('LIN3');
fProgress = (CPatternProgressBar *)fWindow->FindPaneByID('PtPb');
ThrowIfNil_(fLine1);
ThrowIfNil_(fLine2);
ThrowIfNil_(fLine3);
ThrowIfNil_(fProgress);
}
CProgressMac::~CProgressMac()
{
if (fWindow)
delete fWindow;
}
void CProgressMac::SetCancelCallback(PW_CancelCallback incancelcb, /* Callback function for cancel */
void * incancelClosure)
{
fCancelcb = incancelcb;
fCancelClosure = incancelClosure;
LButton * cancelButton = (LButton *)fWindow->FindPaneByID('CNCL');
cancelButton->AddListener(this);
}
void CProgressMac::ListenToMessage( MessageT inMessage, void* ioParam )
{
#pragma unused (ioParam)
if ( inMessage == msg_Cancel)
if (fCancelcb)
fCancelcb(fCancelClosure);
}
void CProgressMac::Show()
{
fWindow->Show();
UDesktop::SelectDeskWindow(fWindow);
}
void CProgressMac::Hide()
{
fWindow->Hide();
}
void CProgressMac::SetWindowTitle(const char * title)
{
LStr255 ptitle;
if (title)
ptitle = title;
fWindow->SetDescriptor(ptitle);
}
void CProgressMac::SetLine1(const char * text)
{
LStr255 ptext;
if (text)
ptext = text;
fLine1->SetDescriptor(ptext);
}
void CProgressMac::SetLine2(const char * text)
{
LStr255 ptext;
if (text)
ptext = text;
fLine2->SetDescriptor(ptext);
}
void CProgressMac::SetProgressText(const char * text)
{
LStr255 ptext;
if (text)
ptext = text;
fLine3->SetDescriptor(ptext);
}
void CProgressMac::SetProgressRange(int32 minimum, int32 maximum)
{
if (maximum > minimum)
{
Range32T r(minimum, maximum);
fProgress->SetValueRange(r);
fProgress->SetValue(minimum);
}
else
{
fProgress->SetToIndefinite();
}
}
void CProgressMac::SetProgressValue(int32 value)
{
fProgress->SetValue(value);
}
#pragma export on
pw_ptr PW_Create( MWContext * /*parent*/, /* Parent window, can be NULL */
PW_WindowType type /* What kind of window ? Modality, etc */
)
{
volatile CProgressMac * mac = NULL;
try
{
mac = new CProgressMac(type);
}
catch(OSErr err)
{
XP_ASSERT(FALSE);
}
if (mac)
{ // Clean up the progress text
PW_SetWindowTitle(mac, NULL);
PW_SetLine1(mac, NULL);
PW_SetLine2(mac, NULL);
}
return mac;
}
void PW_SetCancelCallback(pw_ptr pw,
PW_CancelCallback cancelcb,
void * cancelClosure)
{
if (pw)
((CProgressMac *)pw)->SetCancelCallback(cancelcb, cancelClosure);
}
void PW_Show(pw_ptr pw)
{
if (pw)
((CProgressMac *)pw)->Show();
}
void PW_Hide(pw_ptr pw)
{
if (pw)
((CProgressMac *)pw)->Hide();
}
void PW_Destroy(pw_ptr pw)
{
if (pw)
delete (CProgressMac*)pw;
}
void PW_SetWindowTitle(pw_ptr pw, const char * title)
{
if (pw)
((CProgressMac *)pw)->SetWindowTitle(title);
}
void PW_SetLine1(pw_ptr pw, const char * text)
{
if (pw)
((CProgressMac *)pw)->SetLine1(text);
}
void PW_SetLine2(pw_ptr pw, const char * text)
{
if (pw)
((CProgressMac *)pw)->SetLine2(text);
}
void PW_SetProgressText(pw_ptr pw, const char * text)
{
if (pw)
((CProgressMac *)pw)->SetProgressText(text);
}
void PW_SetProgressRange(pw_ptr pw, int32 minimum, int32 maximum)
{
if (pw)
((CProgressMac *)pw)->SetProgressRange(minimum, maximum);
}
void PW_SetProgressValue(pw_ptr pw, int32 value)
{
if (pw)
((CProgressMac *)pw)->SetProgressValue(value);
}
#pragma export off

View File

@@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* pw_unix.cpp
* Unix implementation of progress interface
*/
#ifndef _WINDOWS
#include "pw_public.h"
pw_ptr PW_Create( MWContext * parent, /* Parent window, can be NULL */
PW_WindowType type /* What kind of window ? Modality, etc */
)
{
return NULL;
}
void PW_SetCancelCallback(pw_ptr pw,
PW_CancelCallback cancelcb,
void * cancelClosure)
{}
void PW_Show(pw_ptr pw)
{}
void PW_Hide(pw_ptr pw)
{}
void PW_Destroy(pw_ptr pw)
{}
void PW_SetWindowTitle(pw_ptr pw, const char * title)
{}
void PW_SetLine1(pw_ptr pw, const char * text)
{}
void PW_SetLine2(pw_ptr pw, const char * text)
{}
void PW_SetProgressText(pw_ptr pw, const char * text)
{}
void PW_SetProgressRange(pw_ptr pw, int32 minimum, int32 maximum)
{}
void PW_SetProgressValue(pw_ptr pw, int32 value)
{}
#endif

View File

@@ -0,0 +1,156 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* pw_win.cpp
* Windows implementation of progress interface
*/
#ifdef _WINDOWS
#include "tooltip.h"
#include <afxwin.h>
#include "resource.h"
#include "pw_public.h"
#include "pw_win.h"
#include "winli.h"
#include "cast.h"
pw_ptr PW_Create( MWContext * parent, /* Parent window, can be NULL */
PW_WindowType type /* What kind of window ? Modality, etc */
)
{
CXPProgressDialog * dlg;
dlg = new CXPProgressDialog();
#ifndef XP_WIN16
/* REMIND: need to fix for win16 */
if (dlg) dlg->Create(IDD_XPPROGRESS,NULL);
#endif
return dlg;
}
void PW_SetCancelCallback(pw_ptr pw,
PW_CancelCallback cancelcb,
void * cancelClosure)
{}
void PW_Show(pw_ptr pw)
{
CXPProgressDialog * dlg;
if (pw) {
dlg = (CXPProgressDialog *)pw;
dlg->ShowWindow(SW_SHOW);
}
}
void PW_Hide(pw_ptr pw)
{
CXPProgressDialog * dlg;
if (pw) {
dlg = (CXPProgressDialog *)pw;
dlg->ShowWindow(SW_HIDE);
}
}
void PW_Destroy(pw_ptr pw)
{
CXPProgressDialog * dlg;
if (pw) {
dlg = (CXPProgressDialog *)pw;
dlg->DestroyWindow();
}
}
void PW_SetWindowTitle(pw_ptr pw, const char * title)
{
CXPProgressDialog * dlg;
if (pw) {
dlg = (CXPProgressDialog *)pw;
dlg->SetWindowText(title);
}
}
void PW_SetLine1(pw_ptr pw, const char * text)
{
CXPProgressDialog * dlg;
if (pw) {
dlg = (CXPProgressDialog *)pw;
dlg->GetDlgItem(IDC_LINE1)->SetWindowText(text);
}
}
void PW_SetLine2(pw_ptr pw, const char * text)
{
CXPProgressDialog * dlg;
if (pw) {
dlg = (CXPProgressDialog *)pw;
dlg->GetDlgItem(IDC_LINE2)->SetWindowText(text);
}
}
void PW_SetProgressText(pw_ptr pw, const char * text)
{
CXPProgressDialog * dlg;
if (pw) dlg = (CXPProgressDialog *)pw;
}
void PW_SetProgressRange(pw_ptr pw, int32 minimum, int32 maximum)
{
CXPProgressDialog * dlg;
if (pw) {
dlg = (CXPProgressDialog *)pw;
dlg->m_Min = minimum;
dlg->m_Max = maximum;
dlg->m_Range = 100;
}
}
void PW_SetProgressValue(pw_ptr pw, int32 value)
{
CXPProgressDialog * dlg;
if (pw) {
dlg = (CXPProgressDialog *)pw;
// dlg->m_ProgressMeter.StepItTo(CASTINT((value*100)/dlg->m_Range));
// char szPercent[10];
// PR_snprintf(szPercent,sizeof(szPercent),"%ld%%",(value*100)/dlg->m_Range);
// dlg->m_PercentComplete.SetWindowText(szPercent);
}
}
#endif

View File

@@ -0,0 +1,18 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/

View File

@@ -0,0 +1,268 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* pwcommon.cpp
* cross-platform progress routines
*/
#include "pw_public.h"
#include "ntypes.h"
#include "structs.h"
#include "proto.h"
#include "xp_mem.h"
#include "fe_proto.h"
#include "ctxtfunc.h"
#include "xp_thrmo.h"
void pw_Progress(MWContext * cx, const char *msg);
void pw_Alert(MWContext * cx, const char *msg);
void pw_GraphProgressInit(MWContext *context, URL_Struct *URL_s, int32 content_length);
void pw_GraphProgressDestroy(MWContext *context, URL_Struct *URL_s, int32 content_length, int32 total_bytes_read);
void pw_GraphProgress(MWContext *context, URL_Struct *URL_s, int32 bytes_received, int32 bytes_since_last_time, int32 content_length);
XP_Bool pw_Confirm(MWContext * context, const char * Msg);
char* pw_Prompt(MWContext * context, const char * Msg, const char * dflt);
char* pw_PromptWithCaption(MWContext * context, const char *caption, const char * Msg, const char * dflt);
XP_Bool pw_PromptUsernameAndPassword(MWContext *,const char *,char **, char **);
char * pw_PromptPassword(MWContext * context, const char * Msg);
void pw_EnableClicking(MWContext * context);
void pw_AllConnectionsComplete(MWContext * context);
void pw_SetProgressBarPercent(MWContext *context, int32 percent);
void pw_SetCallNetlibAllTheTime(MWContext *context);
void pw_ClearCallNetlibAllTheTime(MWContext *context);
/* This struct encapsulates the data we need to store in our progress context */
struct pw_environment_ {
pw_ptr progressWindow;
/* data for progress total calculations */
int outstandingURLs; /* How many outstanding URLs do we have */
XP_Bool hasUnknownSizeURLs; /* How many outstanding URLs have unknown size */
unsigned long total_bytes;
unsigned long bytes_received;
unsigned long start_time_secs;
} ;
typedef struct pw_environment_ pw_environment;
#ifdef XP_MAC
#pragma export on
#endif
MWContext * PW_CreateProgressContext()
{
/* After the merge, it'll be XP_NewCntxt */
pw_environment * p_context;
MWContext * newMWContext;
p_context = (pw_environment *)XP_CALLOC(sizeof(pw_environment), 1);
if (p_context == NULL)
return NULL;
/* initialize the new MWContext */
newMWContext = (MWContext *) XP_CALLOC(sizeof( MWContext ), 1);
if (newMWContext == NULL)
return NULL;
// XP_AddContextToList(newMWContext);
newMWContext->type = MWContextProgressModule;
XP_InitializeContext(newMWContext);
// Assign all the functions
newMWContext->funcs = (ContextFuncs*) XP_ALLOC(sizeof(ContextFuncs));
if (newMWContext->funcs == NULL )
return NULL;
newMWContext->funcs->Progress = pw_Progress;
newMWContext->funcs->Alert = pw_Alert;
newMWContext->funcs->GraphProgressInit = pw_GraphProgressInit;
newMWContext->funcs->GraphProgressDestroy = pw_GraphProgressDestroy;
newMWContext->funcs->GraphProgress = pw_GraphProgress;
newMWContext->funcs->Confirm = pw_Confirm;
newMWContext->funcs->Prompt = pw_Prompt;
newMWContext->funcs->PromptWithCaption = pw_PromptWithCaption;
newMWContext->funcs->PromptUsernameAndPassword = pw_PromptUsernameAndPassword;
newMWContext->funcs->PromptPassword = pw_PromptPassword;
newMWContext->funcs->PromptPassword = pw_PromptPassword;
newMWContext->funcs->EnableClicking = pw_EnableClicking;
newMWContext->funcs->AllConnectionsComplete = pw_AllConnectionsComplete;
newMWContext->funcs->SetProgressBarPercent = pw_SetProgressBarPercent;
newMWContext->funcs->SetCallNetlibAllTheTime = pw_SetCallNetlibAllTheTime;
newMWContext->funcs->ClearCallNetlibAllTheTime = pw_ClearCallNetlibAllTheTime;
newMWContext->mime_data = (struct MimeDisplayData *)p_context; /* Hackily overloading a part of MWContext */
return newMWContext;
}
void PW_DestroyProgressContext(MWContext * context)
{
if (context)
{
// XP_RemoveContextFromList(context);
pw_ptr pw = ((pw_environment *)(context->mime_data))->progressWindow;
XP_FREEIF( context->funcs);
XP_FREEIF(context);
}
}
void PW_AssociateWindowWithContext(MWContext * context, pw_ptr pw)
{
pw_environment * e = (pw_environment *)(context->mime_data);
XP_Bool doReset;
if (context->type != MWContextProgressModule)
{
XP_ASSERT(FALSE);
return;
}
doReset = (e->progressWindow != pw);
e->progressWindow = pw;
if (doReset &&
(pw != NULL))
{
PW_SetProgressText( pw, NULL);
}
}
#ifdef XP_MAC
#pragma export off
#endif
void pw_Progress(MWContext * cx, const char *msg)
{
pw_ptr pw = ((pw_environment *)(cx->mime_data))->progressWindow;
if (pw)
PW_SetLine2(pw, msg);
}
void pw_Alert(MWContext * /*cx*/, const char *msg)
{
FE_Alert(NULL, msg);
}
void pw_GraphProgressInit(MWContext *context, URL_Struct* /*URL_s*/, int32 content_length)
{
pw_environment * pe = (pw_environment *)context->mime_data;
pe->outstandingURLs += 1;
if ( content_length > 0 )
pe->total_bytes += content_length;
else
pe->hasUnknownSizeURLs = TRUE;
if (pe->outstandingURLs == 1) /* First URL got started, set the start time */
pe->start_time_secs = XP_TIME();
}
void pw_GraphProgressDestroy(MWContext *context, URL_Struct* /*URL_s*/, int32 /*content_length*/, int32 /*total_bytes_read*/)
{
pw_environment * pe = (pw_environment *)context->mime_data;
pe->outstandingURLs -= 1;
if ( pe->outstandingURLs == 0)
{
if ( pe->progressWindow )
{
PW_SetProgressText( pe->progressWindow, NULL);
PW_SetProgressRange( pe->progressWindow, 0, 0);
PW_SetProgressValue( pe->progressWindow, 0 );
}
pe->bytes_received = 0;
pe->total_bytes = 0;
pe->start_time_secs = 0;
pe->hasUnknownSizeURLs = FALSE;
}
}
void pw_GraphProgress(MWContext *context, URL_Struct* /*URL_s*/, int32 /*bytes_received*/, int32 bytes_since_last_time, int32 /*content_length*/)
{
pw_environment * pe = (pw_environment *)context->mime_data;
const char * progressText;
pe->bytes_received += bytes_since_last_time;
if (pe->progressWindow)
{
progressText = XP_ProgressText( pe->hasUnknownSizeURLs ? 0 : pe->total_bytes,
pe->bytes_received,
pe->start_time_secs,
XP_TIME());
PW_SetProgressText( pe->progressWindow, progressText);
}
}
void pw_SetProgressBarPercent(MWContext *context, int32 percent)
{
pw_environment * pe = (pw_environment *)context->mime_data;
if (pe->progressWindow)
{
PW_SetProgressValue( pe->progressWindow, percent);
}
}
XP_Bool pw_Confirm(MWContext* /*context*/, const char* /*Msg*/)
{
XP_ASSERT(FALSE);
return FALSE;
// return FE_Confirm(NULL, Msg);
}
char* pw_Prompt(MWContext * /*context*/, const char * /*Msg*/, const char * /*dflt*/)
{
XP_ASSERT(FALSE);
return NULL;
// return FE_Prompt(NULL, Msg, dflt);
}
char* pw_PromptWithCaption(MWContext * /*context */, const char * /* caption */, const char * /*Msg*/, const char * /*dflt*/)
{
return NULL; // FE_PromptWithCaption(NULL, caption, Msg, dflt);
}
XP_Bool pw_PromptUsernameAndPassword(MWContext *,const char * /* prompt */,char ** /* username */ , char ** /* password */)
{
//return FE_PromptUsernameAndPassword(NULL, prompt, username, password);
return FALSE;
}
char * pw_PromptPassword(MWContext * /*context*/, const char * /*Msg*/)
{
// return FE_PromptPassword(NULL, Msg);
return NULL;
}
void pw_EnableClicking(MWContext * /*context*/)
{
}
void pw_AllConnectionsComplete(MWContext * /*context*/)
{
}
void pw_SetCallNetlibAllTheTime(MWContext * /*context*/)
{
XP_ASSERT(FALSE);
}
void pw_ClearCallNetlibAllTheTime(MWContext * /*context*/)
{
XP_ASSERT(FALSE);
}