// @(#)root/gui:$Id$
// Author: Fons Rademakers   15/01/98

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TRootGuiFactory                                                      //
//                                                                      //
// This class is a factory for ROOT GUI components. It overrides        //
// the member functions of the ABS TGuiFactory.                         //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TRootGuiFactory.h"
#include "TRootApplication.h"
#include "TRootCanvas.h"
#include "TRootBrowserLite.h"
#include "TRootContextMenu.h"
#include "TRootControlBar.h"
#include "TROOT.h"
#include "TPluginManager.h"
#include "TEnv.h"

ClassImp(TRootGuiFactory)

//______________________________________________________________________________
TRootGuiFactory::TRootGuiFactory(const char *name, const char *title)
   : TGuiFactory(name, title)
{
   // TRootGuiFactory ctor.
}

//______________________________________________________________________________
TApplicationImp *TRootGuiFactory::CreateApplicationImp(const char *classname,
                      Int_t *argc, char **argv)
{
   // Create a ROOT native GUI version of TApplicationImp

   TRootApplication *app = new TRootApplication(classname, argc, argv);
   if (!app->Client()) {
      delete app;
      app = 0;
   }
   return app;
}

//______________________________________________________________________________
TCanvasImp *TRootGuiFactory::CreateCanvasImp(TCanvas *c, const char *title,
                                             UInt_t width, UInt_t height)
{
   // Create a ROOT native GUI version of TCanvasImp

   return new TRootCanvas(c, title, width, height);
}

//______________________________________________________________________________
TCanvasImp *TRootGuiFactory::CreateCanvasImp(TCanvas *c, const char *title,
                                  Int_t x, Int_t y, UInt_t width, UInt_t height)
{
   // Create a ROOT native GUI version of TCanvasImp

   return new TRootCanvas(c, title, x, y, width, height);
}

//______________________________________________________________________________
TBrowserImp *TRootGuiFactory::CreateBrowserImp(TBrowser *b, const char *title,
                                               UInt_t width, UInt_t height,
                                               Option_t *opt)
{
   // Create a ROOT native GUI version of TBrowserImp

   TString browserVersion(gEnv->GetValue("Browser.Name", "TRootBrowserLite"));
   TPluginHandler *ph = gROOT->GetPluginManager()->FindHandler("TBrowserImp",
                                                               browserVersion);
   TString browserOptions(gEnv->GetValue("Browser.Options", "FECI"));
   if (opt && strlen(opt))
      browserOptions = opt;
   browserOptions.ToUpper();
   if (browserOptions.Contains("LITE"))
      return new TRootBrowserLite(b, title, width, height);
   if (ph && ph->LoadPlugin() != -1) {
      TBrowserImp *imp = (TBrowserImp *)ph->ExecPlugin(5, b, title, width,
         height, browserOptions.Data());
      if (imp) return imp;
   }
   return new TRootBrowserLite(b, title, width, height);
}

//______________________________________________________________________________
TBrowserImp *TRootGuiFactory::CreateBrowserImp(TBrowser *b, const char *title,
                                               Int_t x, Int_t y, UInt_t width,
                                               UInt_t height, Option_t *opt)
{
   // Create a ROOT native GUI version of TBrowserImp

   TString browserVersion(gEnv->GetValue("Browser.Name", "TRootBrowserLite"));
   TPluginHandler *ph = gROOT->GetPluginManager()->FindHandler("TBrowserImp",
                                                               browserVersion);
   TString browserOptions(gEnv->GetValue("Browser.Options", "FECI"));
   if (opt && strlen(opt))
      browserOptions = opt;
   browserOptions.ToUpper();
   if (browserOptions.Contains("LITE"))
      return new TRootBrowserLite(b, title, width, height);
   if (ph && ph->LoadPlugin() != -1) {
      TBrowserImp *imp = (TBrowserImp *)ph->ExecPlugin(7, b, title, x, y, width,
         height, browserOptions.Data());
      if (imp) return imp;
   }
   return new TRootBrowserLite(b, title, x, y, width, height);
}

//______________________________________________________________________________
TContextMenuImp *TRootGuiFactory::CreateContextMenuImp(TContextMenu *c,
                                             const char *name, const char *)
{
   // Create a ROOT native GUI version of TContextMenuImp

   return new TRootContextMenu(c, name);
}

//______________________________________________________________________________
TControlBarImp *TRootGuiFactory::CreateControlBarImp(TControlBar *c, const char *title)
{
   // Create a ROOT native GUI version of TControlBarImp

   return new TRootControlBar(c, title);
}

//______________________________________________________________________________
TControlBarImp *TRootGuiFactory::CreateControlBarImp(TControlBar *c, const char *title,
                                                     Int_t x, Int_t y)
{
   // Create a ROOT native GUI version of TControlBarImp

   return new TRootControlBar(c, title, x, y);
}
 TRootGuiFactory.cxx:1
 TRootGuiFactory.cxx:2
 TRootGuiFactory.cxx:3
 TRootGuiFactory.cxx:4
 TRootGuiFactory.cxx:5
 TRootGuiFactory.cxx:6
 TRootGuiFactory.cxx:7
 TRootGuiFactory.cxx:8
 TRootGuiFactory.cxx:9
 TRootGuiFactory.cxx:10
 TRootGuiFactory.cxx:11
 TRootGuiFactory.cxx:12
 TRootGuiFactory.cxx:13
 TRootGuiFactory.cxx:14
 TRootGuiFactory.cxx:15
 TRootGuiFactory.cxx:16
 TRootGuiFactory.cxx:17
 TRootGuiFactory.cxx:18
 TRootGuiFactory.cxx:19
 TRootGuiFactory.cxx:20
 TRootGuiFactory.cxx:21
 TRootGuiFactory.cxx:22
 TRootGuiFactory.cxx:23
 TRootGuiFactory.cxx:24
 TRootGuiFactory.cxx:25
 TRootGuiFactory.cxx:26
 TRootGuiFactory.cxx:27
 TRootGuiFactory.cxx:28
 TRootGuiFactory.cxx:29
 TRootGuiFactory.cxx:30
 TRootGuiFactory.cxx:31
 TRootGuiFactory.cxx:32
 TRootGuiFactory.cxx:33
 TRootGuiFactory.cxx:34
 TRootGuiFactory.cxx:35
 TRootGuiFactory.cxx:36
 TRootGuiFactory.cxx:37
 TRootGuiFactory.cxx:38
 TRootGuiFactory.cxx:39
 TRootGuiFactory.cxx:40
 TRootGuiFactory.cxx:41
 TRootGuiFactory.cxx:42
 TRootGuiFactory.cxx:43
 TRootGuiFactory.cxx:44
 TRootGuiFactory.cxx:45
 TRootGuiFactory.cxx:46
 TRootGuiFactory.cxx:47
 TRootGuiFactory.cxx:48
 TRootGuiFactory.cxx:49
 TRootGuiFactory.cxx:50
 TRootGuiFactory.cxx:51
 TRootGuiFactory.cxx:52
 TRootGuiFactory.cxx:53
 TRootGuiFactory.cxx:54
 TRootGuiFactory.cxx:55
 TRootGuiFactory.cxx:56
 TRootGuiFactory.cxx:57
 TRootGuiFactory.cxx:58
 TRootGuiFactory.cxx:59
 TRootGuiFactory.cxx:60
 TRootGuiFactory.cxx:61
 TRootGuiFactory.cxx:62
 TRootGuiFactory.cxx:63
 TRootGuiFactory.cxx:64
 TRootGuiFactory.cxx:65
 TRootGuiFactory.cxx:66
 TRootGuiFactory.cxx:67
 TRootGuiFactory.cxx:68
 TRootGuiFactory.cxx:69
 TRootGuiFactory.cxx:70
 TRootGuiFactory.cxx:71
 TRootGuiFactory.cxx:72
 TRootGuiFactory.cxx:73
 TRootGuiFactory.cxx:74
 TRootGuiFactory.cxx:75
 TRootGuiFactory.cxx:76
 TRootGuiFactory.cxx:77
 TRootGuiFactory.cxx:78
 TRootGuiFactory.cxx:79
 TRootGuiFactory.cxx:80
 TRootGuiFactory.cxx:81
 TRootGuiFactory.cxx:82
 TRootGuiFactory.cxx:83
 TRootGuiFactory.cxx:84
 TRootGuiFactory.cxx:85
 TRootGuiFactory.cxx:86
 TRootGuiFactory.cxx:87
 TRootGuiFactory.cxx:88
 TRootGuiFactory.cxx:89
 TRootGuiFactory.cxx:90
 TRootGuiFactory.cxx:91
 TRootGuiFactory.cxx:92
 TRootGuiFactory.cxx:93
 TRootGuiFactory.cxx:94
 TRootGuiFactory.cxx:95
 TRootGuiFactory.cxx:96
 TRootGuiFactory.cxx:97
 TRootGuiFactory.cxx:98
 TRootGuiFactory.cxx:99
 TRootGuiFactory.cxx:100
 TRootGuiFactory.cxx:101
 TRootGuiFactory.cxx:102
 TRootGuiFactory.cxx:103
 TRootGuiFactory.cxx:104
 TRootGuiFactory.cxx:105
 TRootGuiFactory.cxx:106
 TRootGuiFactory.cxx:107
 TRootGuiFactory.cxx:108
 TRootGuiFactory.cxx:109
 TRootGuiFactory.cxx:110
 TRootGuiFactory.cxx:111
 TRootGuiFactory.cxx:112
 TRootGuiFactory.cxx:113
 TRootGuiFactory.cxx:114
 TRootGuiFactory.cxx:115
 TRootGuiFactory.cxx:116
 TRootGuiFactory.cxx:117
 TRootGuiFactory.cxx:118
 TRootGuiFactory.cxx:119
 TRootGuiFactory.cxx:120
 TRootGuiFactory.cxx:121
 TRootGuiFactory.cxx:122
 TRootGuiFactory.cxx:123
 TRootGuiFactory.cxx:124
 TRootGuiFactory.cxx:125
 TRootGuiFactory.cxx:126
 TRootGuiFactory.cxx:127
 TRootGuiFactory.cxx:128
 TRootGuiFactory.cxx:129
 TRootGuiFactory.cxx:130
 TRootGuiFactory.cxx:131
 TRootGuiFactory.cxx:132
 TRootGuiFactory.cxx:133
 TRootGuiFactory.cxx:134
 TRootGuiFactory.cxx:135
 TRootGuiFactory.cxx:136
 TRootGuiFactory.cxx:137
 TRootGuiFactory.cxx:138
 TRootGuiFactory.cxx:139
 TRootGuiFactory.cxx:140
 TRootGuiFactory.cxx:141
 TRootGuiFactory.cxx:142
 TRootGuiFactory.cxx:143
 TRootGuiFactory.cxx:144