//
// Copyright (C) 1999-2002 Toshikaz Hirabayashi
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// TOSHIKAZ HIRABAYASHI BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// Except as contained in this notice, the name of Toshikaz Hirabayashi shall
// not be used in advertising or otherwise to promote the sale, use or other
// dealings in this Software without prior written authorization from
// Toshikaz Hirabayashi.

#include <mac/WSDmacAppDev.h>
#include <mac/WSDmacColor.h>
#include <mac/WSDmacMouse.h>
#include <WSCcolorSet.h>
#include <WSCimageSet.h>
#include <WSDdev.h>
#include <mac/WSDmacDraw.h>


#include <../../sys/pixmaps/bi13.xpm>
#include <../../sys/pixmaps/bi15.xpm>
#include <../../sys/pixmaps/bi16.xpm>
#include <../../sys/pixmaps/bi17.xpm>
#include <../../sys/pixmaps/bi18.xpm>
#include <../../sys/pixmaps/bi19.xpm>
#include <../../sys/pixmaps/endbtn.xpm>

#include <../../sys/pixmaps/bi4.xpm>
#include <../../sys/pixmaps/bi23.xpm>
#include <../../sys/pixmaps/bi24.xpm>
#include <../../sys/pixmaps/bi25.xpm>
#include <../../sys/pixmaps/ope.xpm>
#include <../../sys/pixmaps/wcreate.xpm>
#include <../../sys/pixmaps/wtrash.xpm>
#include <../../sys/pixmaps/edit.xpm>
#include <../../sys/pixmaps/pset.xpm>

#include <../../sys/pixmaps/bi8.xpm>
#include <../../sys/pixmaps/pcreate.xpm>
#include <../../sys/pixmaps/pload.xpm>
#include <../../sys/pixmaps/psave.xpm>
#include <../../sys/pixmaps/pend.xpm>
#include <../../sys/pixmaps/wload.xpm>
#include <../../sys/pixmaps/wsave.xpm>
#include <../../sys/pixmaps/obox.xpm>
#include <../../sys/pixmaps/make.xpm>
#include <../../sys/pixmaps/run.xpm>
#include <../../sys/pixmaps/search.xpm>
#include <../../sys/pixmaps/search2.xpm>
#include <../../sys/pixmaps/help.xpm>
#include <../../sys/pixmaps/runx.xpm>
#include <../../sys/pixmaps/al.xpm>
#include <../../sys/pixmaps/ml.xpm>
#include <../../sys/pixmaps/ar.xpm>
#include <../../sys/pixmaps/mr.xpm>
#include <../../sys/pixmaps/am.xpm>
#include <../../sys/pixmaps/alv.xpm>
#include <../../sys/pixmaps/mlv.xpm>
#include <../../sys/pixmaps/arv.xpm>
#include <../../sys/pixmaps/mrv.xpm>
#include <../../sys/pixmaps/amv.xpm>
#include <../../sys/pixmaps/rl.xpm>
#include <../../sys/pixmaps/rm.xpm>
#include <../../sys/pixmaps/rr.xpm>
#include <../../sys/pixmaps/mrl.xpm>
#include <../../sys/pixmaps/mrr.xpm>

//#define TDBG

int main1(int argc,char** argv){
#ifdef TDBG
printf("main start:\n");
WSMFtrace("main start:\n");
WSGFsetTimePoint();
#endif
   WSDdev::setDraw(new WSDmacDraw());
   assert( WSGIappDev() );

   extern void _macImage_init();
   _macImage_init();
#if 0
   WSCstring* copyright = WSGFreadTextFile("$(WSDIR)/sys/data/copyright");
   if (copyright != NULL){
     printf("%s",copyright->getString());
     delete copyright;
   }
#endif
   WSDappDev* app = WSGIappDev();
   WSDmacAppDev* mapp = (WSDmacAppDev*)app->cast("WSDmacAppDev");
   if (argc != 0){
     mapp->setInitPrm(argc,argv);
   }
   mapp->initialize();
   WSGImacAppMouse()->initialize();

   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/pcreate.xpm",pcreate_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/pload.xpm",pload_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/psave.xpm",psave_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/pend.xpm",pend_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/wload.xpm",wload_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/wsave.xpm",wsave_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/obox.xpm",obox_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/make.xpm",make_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/run.xpm",run_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/search.xpm",search_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/search2.xpm",search2_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/help.xpm",help_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/runx.xpm",runx_xpm);

   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi4.xpm",bi4_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi4.xpm",bi8_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi13.xpm",bi13_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi15.xpm",bi15_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi16.xpm",bi16_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi17.xpm",bi17_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi18.xpm",bi18_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi19.xpm",bi19_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi23.xpm",bi23_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi24.xpm",bi24_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/bi25.xpm",bi25_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/endbtn.xpm",endbtn_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/ope.xpm",ope_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/wcreate.xpm",wcreate_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/wtrash.xpm",wtrash_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/edit.xpm",edit_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/pset.xpm",pset_xpm);

   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/al.xpm",al_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/ml.xpm",ml_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/ar.xpm",ar_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/mr.xpm",mr_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/am.xpm",am_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/alv.xpm",alv_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/mlv.xpm",mlv_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/arv.xpm",arv_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/mrv.xpm",mrv_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/amv.xpm",amv_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/rr.xpm",rr_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/rm.xpm",rm_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/rl.xpm",rl_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/mrr.xpm",mrr_xpm);
   WSGIappImageSet()->setDefaultImageHandle("$(WSDIR)/sys/pixmaps/mrl.xpm",mrl_xpm);

   mapp->execInitHandler();
//  WSDxcolor::restart_blink_server();

   extern void _macfonts_init_();
   _macfonts_init_();

#ifdef TDBG
printf("main init done.:%d\n",WSGFdiffTimePoint());
WSMFtrace("main init done.:%d\n",WSGFdiffTimePoint());
#endif
  return 0;
}

int WSGFwsInitialize(){
  main1(0,NULL);
  return 0;
}

int main(int argc,char** argv){
  main1(argc,argv);
  WSDappDev* app = WSGIappDev();
  WSDmacAppDev* mapp = (WSDmacAppDev*)app->cast("WSDmacAppDev");
  mapp->handleEvents();
  return 0;
}

