// @(#)root/gui:$Id$
// Author: Fons Rademakers   27/12/97

/*************************************************************************
 * 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.             *
 *************************************************************************/

#ifndef ROOT_TGClient
#define ROOT_TGClient


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGClient                                                             //
//                                                                      //
// Window client. In client server windowing systems, like X11 this     //
// class is used to make the initial connection to the window server.   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_GuiTypes
#include "GuiTypes.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TQObject
#include "TQObject.h"
#endif


class TList;
class THashList;
class TGWindow;
class TGResourcePool;
class TGPicturePool;
class TGPicture;
class TGGCPool;
class TGGC;
class TGFontPool;
class TGFont;
class TGMimeTypes;
class TGUnknownWindowHandler;
class TGIdleHandler;


class TGClient : public TObject, public TQObject {

friend class TGCocoa;

protected:
   Pixel_t         fBackColor;        // default background color
   Pixel_t         fForeColor;        // default foreground color
   Pixel_t         fHilite;           // default hilite color
   Pixel_t         fShadow;           // default shadow color
   Pixel_t         fSelBackColor;     // default selection background color
   Pixel_t         fSelForeColor;     // default selection foreground color
   Pixel_t         fWhite;            // white color index
   Pixel_t         fBlack;            // black color index
   TGWindow       *fDefaultRoot;      // default root window (base window of display)
   TGWindow       *fRoot;             // current root window (changing root window allows embedding)
   Int_t           fXfd;              // file descriptor of connection to server
   TGResourcePool *fResourcePool;     // global GUI resource pool
   TGGCPool       *fGCPool;           // graphics context pool
   TGFontPool     *fFontPool;         // font pool
   TGPicturePool  *fPicturePool;      // pixmap pool
   TGMimeTypes    *fMimeTypeList;     // mimetype list
   Colormap_t      fDefaultColormap;  // default colormap
   Bool_t          fGlobalNeedRedraw; // true if at least one window needs to be redrawn
   Bool_t          fForceRedraw;      // redraw widgets as soon as possible
   THashList      *fWlist;            // list of frames
   TList          *fPlist;            // list of popup windows used in HandleMaskEvent()
   TList          *fUWHandlers;       // list of event handlers for unknown windows
   TList          *fIdleHandlers;     // list of idle handlers
   EGEventType     fWaitForEvent;     // event to wait for
   Window_t        fWaitForWindow;    // window in which to wait for event
   UInt_t          fStyle;            // GUI style (modern or classic)

   TGClient(const TGClient&);             // not implemented
   TGClient& operator=(const TGClient&);  // not implemented

   Bool_t  ProcessOneEvent();
   Bool_t  ProcessIdleEvent();
   Bool_t  DoRedraw();

public:
   TGClient(const char *dpyName = 0);
   virtual ~TGClient();

   const TGWindow *GetRoot() const;
   const TGWindow *GetDefaultRoot() const;
   void            SetRoot(TGWindow *root = 0);
   TGWindow       *GetWindowById(Window_t sw) const;
   TGWindow       *GetWindowByName(const char *name) const;

   UInt_t       GetDisplayWidth() const;
   UInt_t       GetDisplayHeight() const;

   Bool_t       IsEditable() const { return fRoot != fDefaultRoot; }
   Bool_t       IsEditDisabled() const;
   void         SetEditDisabled(Bool_t on = kTRUE);

   FontStruct_t GetFontByName(const char *name, Bool_t fixedDefault = kTRUE) const;
   Bool_t       GetColorByName(const char *name, Pixel_t &pixel) const;
   Pixel_t      GetHilite(Pixel_t base_color) const;
   Pixel_t      GetShadow(Pixel_t base_color) const;
   void         FreeColor(Pixel_t color) const;
   void         ForceRedraw() { fForceRedraw = kTRUE; }
   void         NeedRedraw(TGWindow *w, Bool_t force = kFALSE);
   void         CancelRedraw(TGWindow *w);
   void         RegisterWindow(TGWindow *w);
   void         UnregisterWindow(TGWindow *w);
   void         RegisterPopup(TGWindow *w);
   void         UnregisterPopup(TGWindow *w);
   void         AddUnknownWindowHandler(TGUnknownWindowHandler *h);
   void         RemoveUnknownWindowHandler(TGUnknownWindowHandler *h);
   void         AddIdleHandler(TGIdleHandler *h);
   void         RemoveIdleHandler(TGIdleHandler *h);
   Bool_t       HandleInput();
   void         ProcessLine(TString cmd, Long_t msg, Long_t parm1, Long_t parm2);
   void         WaitFor(TGWindow *w);
   void         WaitForUnmap(TGWindow *w);
   void         ResetWaitFor(TGWindow *w);
   EGEventType  GetWaitForEvent() const  { return fWaitForEvent;}
   Window_t     GetWaitForWindow() const { return fWaitForWindow; }
   void         SetWaitForWindow(Window_t wid) {fWaitForWindow = wid;}
   Bool_t       ProcessEventsFor(TGWindow *w);

   Bool_t       HandleEvent(Event_t *event);
   Bool_t       HandleMaskEvent(Event_t *event, Window_t wid);
   void         RegisteredWindow(Window_t w);      //*SIGNAL*
   void         ProcessedEvent(Event_t *event, Window_t wid);   //*SIGNAL*

   const TGResourcePool *GetResourcePool() const { return fResourcePool; }

   TGPicturePool   *GetPicturePool() const { return fPicturePool; }
   const TGPicture *GetPicture(const char *name);
   const TGPicture *GetPicture(const char *name, UInt_t new_width, UInt_t new_height);
   void             FreePicture(const TGPicture *pic);

   TGGCPool        *GetGCPool() const { return fGCPool; }
   TGGC            *GetGC(GCValues_t *values, Bool_t rw = kFALSE);
   void             FreeGC(const TGGC *gc);
   void             FreeGC(GContext_t gc);

   TGFontPool      *GetFontPool() const { return fFontPool; }
   TGFont          *GetFont(const char *font, Bool_t fixedDefault = kTRUE);
   TGFont          *GetFont(const TGFont *font);
   void             FreeFont(const TGFont *font);

   UInt_t           GetStyle() const { return fStyle; }
   void             SetStyle(UInt_t newstyle) { fStyle = newstyle; }
   void             SetStyle(const char *style);

   Colormap_t       GetDefaultColormap() const { return fDefaultColormap; }
   TGMimeTypes     *GetMimeTypeList() const { return fMimeTypeList; }

   THashList       *GetListOfWindows() const { return fWlist; }
   TList           *GetListOfPopups() const { return fPlist; }

   static TGClient *Instance();

   ClassDef(TGClient,0)  // Class making connection to display server
};

#ifndef __CINT__
#define gClient (TGClient::Instance())
#endif

#endif
 TGClient.h:1
 TGClient.h:2
 TGClient.h:3
 TGClient.h:4
 TGClient.h:5
 TGClient.h:6
 TGClient.h:7
 TGClient.h:8
 TGClient.h:9
 TGClient.h:10
 TGClient.h:11
 TGClient.h:12
 TGClient.h:13
 TGClient.h:14
 TGClient.h:15
 TGClient.h:16
 TGClient.h:17
 TGClient.h:18
 TGClient.h:19
 TGClient.h:20
 TGClient.h:21
 TGClient.h:22
 TGClient.h:23
 TGClient.h:24
 TGClient.h:25
 TGClient.h:26
 TGClient.h:27
 TGClient.h:28
 TGClient.h:29
 TGClient.h:30
 TGClient.h:31
 TGClient.h:32
 TGClient.h:33
 TGClient.h:34
 TGClient.h:35
 TGClient.h:36
 TGClient.h:37
 TGClient.h:38
 TGClient.h:39
 TGClient.h:40
 TGClient.h:41
 TGClient.h:42
 TGClient.h:43
 TGClient.h:44
 TGClient.h:45
 TGClient.h:46
 TGClient.h:47
 TGClient.h:48
 TGClient.h:49
 TGClient.h:50
 TGClient.h:51
 TGClient.h:52
 TGClient.h:53
 TGClient.h:54
 TGClient.h:55
 TGClient.h:56
 TGClient.h:57
 TGClient.h:58
 TGClient.h:59
 TGClient.h:60
 TGClient.h:61
 TGClient.h:62
 TGClient.h:63
 TGClient.h:64
 TGClient.h:65
 TGClient.h:66
 TGClient.h:67
 TGClient.h:68
 TGClient.h:69
 TGClient.h:70
 TGClient.h:71
 TGClient.h:72
 TGClient.h:73
 TGClient.h:74
 TGClient.h:75
 TGClient.h:76
 TGClient.h:77
 TGClient.h:78
 TGClient.h:79
 TGClient.h:80
 TGClient.h:81
 TGClient.h:82
 TGClient.h:83
 TGClient.h:84
 TGClient.h:85
 TGClient.h:86
 TGClient.h:87
 TGClient.h:88
 TGClient.h:89
 TGClient.h:90
 TGClient.h:91
 TGClient.h:92
 TGClient.h:93
 TGClient.h:94
 TGClient.h:95
 TGClient.h:96
 TGClient.h:97
 TGClient.h:98
 TGClient.h:99
 TGClient.h:100
 TGClient.h:101
 TGClient.h:102
 TGClient.h:103
 TGClient.h:104
 TGClient.h:105
 TGClient.h:106
 TGClient.h:107
 TGClient.h:108
 TGClient.h:109
 TGClient.h:110
 TGClient.h:111
 TGClient.h:112
 TGClient.h:113
 TGClient.h:114
 TGClient.h:115
 TGClient.h:116
 TGClient.h:117
 TGClient.h:118
 TGClient.h:119
 TGClient.h:120
 TGClient.h:121
 TGClient.h:122
 TGClient.h:123
 TGClient.h:124
 TGClient.h:125
 TGClient.h:126
 TGClient.h:127
 TGClient.h:128
 TGClient.h:129
 TGClient.h:130
 TGClient.h:131
 TGClient.h:132
 TGClient.h:133
 TGClient.h:134
 TGClient.h:135
 TGClient.h:136
 TGClient.h:137
 TGClient.h:138
 TGClient.h:139
 TGClient.h:140
 TGClient.h:141
 TGClient.h:142
 TGClient.h:143
 TGClient.h:144
 TGClient.h:145
 TGClient.h:146
 TGClient.h:147
 TGClient.h:148
 TGClient.h:149
 TGClient.h:150
 TGClient.h:151
 TGClient.h:152
 TGClient.h:153
 TGClient.h:154
 TGClient.h:155
 TGClient.h:156
 TGClient.h:157
 TGClient.h:158
 TGClient.h:159
 TGClient.h:160
 TGClient.h:161
 TGClient.h:162
 TGClient.h:163
 TGClient.h:164
 TGClient.h:165
 TGClient.h:166
 TGClient.h:167
 TGClient.h:168
 TGClient.h:169
 TGClient.h:170
 TGClient.h:171
 TGClient.h:172
 TGClient.h:173
 TGClient.h:174
 TGClient.h:175
 TGClient.h:176
 TGClient.h:177