/*  KBReportViewer							*/
/*  startupNew	: Start reprt viewer object for new report		*/
/*  _location	: KBLocation &	 : Document location			*/
/*  pError	: KBError &	 : Error return				*/
/*  (returns)	: bool		 : Success				*/

bool	KBReportViewer::startupNew
	(	KBLocation	&_location,
		KBError		&pError
	)
{
	location  = _location	;
	viewState = KB::VSDesign;
	writer	  = 0		;

	KBAttrDict	aList	;

	aList.addValue ("language", "el"	  ) ;
	aList.addValue ("caption",  "Uncaptioned" ) ;
	aList.addValue ("autosync", "Yes"	  ) ;
	aList.addValue ("rowcount", "1"	    	  ) ;
	aList.addValue ("name",	    "UnnamedReprt") ;
	aList.addValue ("w",	    KBOptions::getFormWidth ()) ;
	aList.addValue ("h",	    KBOptions::getFormHeight()) ;
	aList.addValue ("dx",	    KBOptions::getDefaultDX ()) ;
	aList.addValue ("dy",	    KBOptions::getDefaultDY ()) ;

	bool	ok ;
	docRoot	= new KBReport (location, aList, ok) ;

	/* If the root constructor returns an error then it must be	*/
	/* because the user has cancelled. Although we destroy		*/
	/* ourselves, this is not really an error.			*/
	if (!ok)
	{	pError	= KBError () ;
		return	false	     ;
	}

	writer	  = new KBWriter (partWidget) ;
	report	  = docRoot->buildGUI  (partWidget) ;
	topWidget = report ;

	docRoot->setWriter (writer) ;

	QSize size = docRoot->setDesignMode (true) ;

	partWidget->resize	  (size + QSize (16, 16))  ;
#ifdef	_QWS
	partWidget->setCaption    ("Untitled") ;
#else
	partWidget->setMDICaption ("Untitled") ;
#endif
	partWidget->setIcon	  (SmallIcon ("document")) ;
	writer	  ->resize 	  (size + QSize (16, 16))  ;
	writer    ->hide   	  () ;

	setGUI    (designGUI) ;
	partWidget->show   () ;

	return	true	      ;
}

/*  KBReportViewer							*/
/*  startupOld	: Startup report viewer object for extant report	*/
/*  _location	: KBLocation &	 : Document location			*/
/*  _design	: bool		 : Open in design mode			*/
/*  pDict	: QDict<QString>&: Parameter dictionary			*/
/*  pError	: KBError &	 : Error return				*/
/*  (returns)	: bool		 : Success				*/

bool	KBReportViewer::startupOld
	(	KBLocation	&_location,
		bool		_design,
		QDict<QString>	&pDict,
		KBError		&pError
	)
{
	/* Note the location and the design/data mode flag, then get	*/
	/* the document. If there is an error here then return at once.	*/
	location  = _location	;
	viewState = _design ? KB::VSDesign : KB::VSData ;

	QString doc = location.contents (pError) ;
	if (doc.isNull())
		return	false	;

	/* Open the report using the document text; if this fails then	*/
	/* again return failure. However, from after this point, we	*/
	/* always return success, although we may force design mode in	*/
	/* the event of further errors.					*/
	if ((docRoot = KBOpenReportText (location, doc, pDict, pError)) == 0)
		return	false	;

	/* Set up the document. If this fails then display the error	*/
	/* and switch to design mode.					*/
	if (!docRoot->setup ())
	{	docRoot->lastError().display () ;
		viewState = KB::VSDesign	;
		_design	  = true		;
	}

	connect	(docRoot->getDocRoot(), SIGNAL (execError()),
		 this,			SLOT   (execError())) ;

	/* Create a new report writer object, then build the GUI (in a	*/
	/* report used only for design) and associate the writer with	*/
	/* the report.							*/
	writer	= new KBWriter (partWidget) ;
	report	= docRoot->buildGUI  (partWidget) ;

	docRoot->setWriter (writer) ;

	QSize size = docRoot->setDesignMode (_design) ;

	if (!_design)
		if (!docRoot->execute())
		{	docRoot->lastError().display() ;
			size      = docRoot->setDesignMode(true) ;
			viewState = KB::VSDesign	;
			_design   = true ;
		}

#ifdef	_QWS
	partWidget->setCaption    (location.docName) ;
#else
	partWidget->setMDICaption (location.docName) ;
#endif
	partWidget->setIcon	  (SmallIcon ("document")) ;

	if (_design)
		showDesign (size) ;
	else	showData   (size) ;

	partWidget->show   () ;
	return	true	    ;
}

