#ifndef CODE_ABOUTDIALOG_CXX
#define CODE_ABOUTDIALOG_CXX

/*-----------------------------------------------------------------------
 * Xclasses code file
 * ($Id: about_dialog.cxx,v 1.6 1999/11/22 11:26:45 schmitzj Exp $)
 * 
 * Copyright (C) 1998 Jürgen Schmitz
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 *-----------------------------------------------------------------------
 */

#include <string.h>
#include "types.h"
#include <Xclasses/tools.h>
#include <Xclasses/Xcolors.h>
#include <Xclasses/group.h>
#include <Xclasses/bordergroup.h>
#include <Xclasses/text.h>
#include <Xclasses/card.h>
#include <Xclasses/output.h>
#include <Xclasses/autotextbox.h>
#include <Xclasses/htmltextbox.h>
#include <Xclasses/html_gadget.h>
#include <Xclasses/fbutton.h>
#include <Xclasses/button.h>
#include <Xclasses/lefttext.h>
#include <Xclasses/visible.h>
#include <Xclasses/appwindow.h>
#include <Xclasses/ruler.h>
#include <Xclasses/image.h>

// #include <Xclasses/about_dialog.h>
#include "../include/about_dialog.h"
#include "include/about_dialog_p.h"
#include "../include/XCprogram_p.h"

about_dialog::about_dialog(int flag) : Xcolors()
{
	p=NULL;
	if (FindObject(".about_dialog"))
	{
		Name("about_dialog_dummy");
		return;
	}
	while (!(p=new pabout_dialog))
	{
		outOfMemory("about_dialog");
	}
	p->o=this;
	Name("about_dialog");
}
pabout_dialog::pabout_dialog() : callable()
{
}
pabout_dialog::~pabout_dialog()
{
}
about_dialog::~about_dialog()
{
	DeleteObjectTree(FullName(),DOT_NOTBASE);
	if (p) delete p;
}

void pabout_dialog::Close(gadget *g,int i)
{
	appwindow *aw=(appwindow*)FindObject(o->FullName(),".window");
	aw->Close();
	delete o;
}
void pabout_dialog::About(gadget *g,int i)
{
	appwindow *aw=(appwindow*)FindObject(o->FullName(),".window");
	about_Xclasses(aw,o);
}
int about_dialog::Start(Xwindows *w)
{
//	int i,ende;
	int x,y;
	XWindowAttributes xwa;

	if (!p) return 0;

	appwindow *mywin=new appwindow;

	mywin->ParentClass(this);
	mywin->Name("window");
	mywin->Callback(p,(CLOSECALLBACK)&pabout_dialog::Close);

	group *maingp=new group;
	maingp->Name("maingroup");
	maingp->Vert();

	card *allcard=new card;
	allcard->Name("allcard");
	maingp->Add(allcard);

	button *but=new fbutton;
	but->Name("okbutton");
	maingp->Add(but);

	 but->Text("_Ok");
	 but->Callback(p,(CALLBACK)&pabout_dialog::Close);
	 but->ApplyXKey(XK_Escape);

	 group *gp;	
	 bordergroup *bgp=new bordergroup;
	 allcard->Add("Program",bgp);

	  bgp->Horiz();
	  if (thisProgram->gfx)
	  {
	  		image *pimg=new image;
	   		bgp->XDistance(5);
	   		bgp->Add(pimg);
	   		 pimg->Object(thisProgram->gfx);
		 	if (thisProgram->ownhtml || thisProgram->owntext)
			  bgp->Vert();
	   }

      gp=new group;
      gp->Name(NULL);
      bgp->Add(gp);
	   gp->Vert();
	   output *op=new output;
	   gp->Add(op);
	    op->Text(" ");
	    op->Output(thisProgram->name->Name());

	   if (thisProgram->desc)
	   {
	   	  op=new output;
		  gp->Add(op);
		   op->Text(" ");
		   op->Output(thisProgram->desc);
	   }

	   op=new output;
	   gp->Add(op);
	    op->Text("Version");
	    op->Output(thisProgram->version?thisProgram->version:(char*)"unknown");
	   op=new output;
	   gp->Add(op);
	    op->Text("Copyright");
	    op->Output(thisProgram->copyright?thisProgram->copyright:(char*)"unknown");

	   lefttext *lt=new lefttext;
	   group *gp2=new group;
       gp->Add(lt);
        lt->Gadget(gp2);
         gp2->Horiz();
         gp2->UseSmallest();
         text *txt=new text;
         gp2->Add(txt);
          txt->FixedText();
          txt->Font(FONT_SMALL);
          txt->Text("This program uses\nXclasses layout library");
         but=new button;
	     gp2->Add(but);
          but->Text("about Xclasses...");
          but->Font(FONT_SMALL);
          but->Callback(p,(CALLBACK)&pabout_dialog::About);

	 bgp=new bordergroup;
	 allcard->Add("Author",bgp);
	  bgp->Vert();
	  if (!thisProgram->mauthors) // || thisProgram->author)
	  {
	    	op=new output;
	  		bgp->Add(op);
	   		 op->Text("Author");
	   		 op->Output(thisProgram->author?thisProgram->author:(char*)"unknown");
	  		if (thisProgram->address)
	   		{
	   			op=new output;
		  		bgp->Add(op);
		   		 op->Text("Address");
		   		 op->Output(thisProgram->address);
			}
			if (thisProgram->email)
			{
				op=new output;
				bgp->Add(op);
				 op->Text("EMail");
				 op->Output(thisProgram->email);
			}
	  }
	  if (thisProgram->mauthors)
	  {
	    struct moreauthor *a=thisProgram->author2;
	    ruler *rl;
		visible *vis=new visible;
		gp=new group;
		bgp->YDistance(4);
		bgp->Add(vis);
		 vis->Apply(gp);
		  gp->Vert();
		  if (thisProgram->sortbyjob)
		  {
			  while (a)
			  {
			  	 if (a->what)
		  		 {
 			  	 	op=new output;
 			  	 	gp->Add(op);
 			  	  	 op->Text("");
 		  		  	 op->Output(a->what);
			  	 }
			  	 op=new output;
		  		 gp->Add(op);
			  	  op->Text("by");
			  	  op->Output(a->author);
			  	 if (a->email)
			  	 {
		  		 	op=new output;
			  	 	gp->Add(op);
			  	  	 op->Text("EMail");
			  	  	 op->Output(a->email);
		  		 }
			  	 if (a->next)
			  	 {
				  	 rl=new ruler;
				  	 gp->Add(rl);
			  		  rl->Horiz();
				 }
    	        a=a->next;
			  }
  		  }
		  else
		  {
			  while (a)
			  {
			  	 op=new output;
		  		 gp->Add(op);
			  	  op->Text("Author");
			  	  op->Output(a->author);
			  	 if (a->what)
		  		 {
			  	 	op=new output;
			  	 	gp->Add(op);
			  	  	 op->Text("did");
		  		  	 op->Output(a->what);
			  	 }
			  	 if (a->email)
			  	 {
		  		 	op=new output;
			  	 	gp->Add(op);
			  	  	 op->Text("EMail");
			  	  	 op->Output(a->email);
		  		 }
			  	 if (a->next)
			  	 {
				  	 rl=new ruler;
				  	 gp->Add(rl);
			  		  rl->Horiz();
				 }
    	        a=a->next;
			  }
		  }
	  }
	  if (thisProgram->www)
	  {
		op=new output;
		bgp->Add(op);
		 op->Text("World-Wide-Web");
		 op->Output(thisProgram->www);
	  }
	  
	 if (thisProgram->owntext)
	 {
	    gp=new group;
	    autotextbox *atb=new autotextbox;
	 	allcard->Add("Author's words",gp);
	 	 gp->Add(atb);
	 	  atb->ReadOnly();
	 	  atb->AppendText(thisProgram->owntext);
	 }
	 else if (thisProgram->ownhtml)
	 {
	    gp=new group;
	    html_gadget *htb=new html_gadget;
	 	allcard->Add("Author's words",gp);
	 	 gp->Add(htb);
		  char *buf=new char[strlen(thisProgram->ownhtml)+strlen("<body>\n\n</body>\n")];
		  strcpy(buf,"<body>\n");
		  strcat(buf,thisProgram->ownhtml);
		  strcat(buf,"\n</body>\n");
	 	  htb->Text(buf);
	 }

	GetPositionOnRoot(display(),w->window(),x,y);
	XGetWindowAttributes(display(),w->window(),&xwa);

	mywin->InitSize(x,y,40);
	mywin->Init();
//	mywin->TransientFor(w);
	mywin->SetGroup(maingp);
	mywin->Adjust(x+xwa.x,y+xwa.y,xwa.width,xwa.height,ADJUST_CENTER|ADJUST_MIDDLE);
	mywin->Title(thisProgram->name->Name());
	mywin->IconTitle(thisProgram->name->Name());
	mywin->Create();
	return 1;
}

#endif
