ROOT logo
// Author: Roel Aaij 21/07/2007

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

#include "TGTableCell.h"
#include "TClass.h"
#include "TGWindow.h"
#include "TGResourcePool.h"
#include "Riostream.h"
#include "TSystem.h"
#include "TImage.h"
#include "TEnv.h"
#include "TGToolTip.h"
#include "TGWidget.h"
#include "TGPicture.h"
#include "TGTable.h"
#include "TRandom3.h"

ClassImp(TGTableHeader)

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGTableHeader                                                        //
//                                                                      //
// TGTableHeader is the class that implements a header for a row or     //
// column. Interactivity on a per column or row basis is implemented    //
// using this header.                                                   //
//                                                                      //
// TGTableHeader is for internal use in TGTable only.                   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

//______________________________________________________________________________
TGTableHeader::TGTableHeader(const TGWindow *p, TGTable *table, TGString *label,
                             UInt_t position, EHeaderType type, UInt_t width, 
                             UInt_t height, GContext_t norm, FontStruct_t font, 
                             UInt_t option)
   : TGTableCell(p, table, label, 0, 0, width, height, norm, font, option, 
                 kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE), 
     fHasOwnLabel(kFALSE)
{
   // TGTableHeader constuctor.

   if (type == kColumnHeader) {
      fWidth = table->GetTableHeader()->GetWidth();
      fHeight = 25;
      fRow = 0;
      fColumn = position;
   } else if (type == kRowHeader) {
      fWidth = 80;
      fHeight = table->GetTableHeader()->GetHeight();
      fRow = position;
      fColumn = 0;
   } else {
      fWidth = 80;
      fHeight = 25;
   }

   if (!label) {
      SetDefaultLabel();
   } else {
      fHasOwnLabel = kTRUE;
   }

   Init();
}

//______________________________________________________________________________
TGTableHeader::TGTableHeader(const TGWindow *p, TGTable *table,  
                             const char *label, UInt_t position, 
                             EHeaderType type, UInt_t width, UInt_t height, 
                             GContext_t norm, FontStruct_t font, UInt_t option)
   : TGTableCell(p, table, label, 0, 0, width, height, norm, font, 
                 option, kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE), 
     fHasOwnLabel(kFALSE)
{
   // TGTableHeader constuctor.

   if (type == kColumnHeader) {
      fWidth = table->GetTableHeader()->GetWidth();
      fHeight = 25;
      fRow = 0;
      fColumn = position;
   } else if (type == kRowHeader) {
      fWidth = 80;
      fHeight = table->GetTableHeader()->GetHeight();
      fRow = position;
      fColumn = 0;
   } else {
      fWidth = 80;
      fHeight = 25;
   }

   if (!label) {
      SetDefaultLabel();
   } else {
      fHasOwnLabel = kTRUE;
   }

   Init();
}


//______________________________________________________________________________
TGTableHeader::~TGTableHeader()
{
   // TGTableHeader destructor.
}

//______________________________________________________________________________
void TGTableHeader::Init()
{
   // Initialize the TGTableHeader   

   if (fType == kTableHeader) {
      SetBackgroundColor(fTable->GetBackground());
   } else {
      SetBackgroundColor(fTable->GetHeaderBackground());
   }

   Resize(fWidth, fHeight);      

   Int_t max_ascent = 0, max_descent = 0;

   fTWidth  = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
   gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
   fTHeight = max_ascent + max_descent;

}

//______________________________________________________________________________
void TGTableHeader::SetWidth(UInt_t width)
{
   // Resize the TGTableHeader.

   Resize(width, GetDefaultHeight());
}

//______________________________________________________________________________
void TGTableHeader::SetHeight(UInt_t height)
{
   // Resize the TGTableHeader.

   Resize(GetDefaultWidth(), height);
}

//______________________________________________________________________________
void TGTableHeader::SetLabel(const char *label)
{
   // Set the label of the TGTableHeader to label.

   if(label) {
      TGTableCell::SetLabel(label);
   } else {
      SetDefaultLabel();
   }
}

//______________________________________________________________________________
void TGTableHeader::SetDefaultLabel()
{
   // Set the label of the TGTableHeader to the default label, "Row #"
   // or "Col #".

   fHasOwnLabel = kFALSE;
   if (fLabel) delete fLabel;
   fLabel = new TGString();
   if (fType == kRowHeader) {
      *fLabel += "Row ";
      *fLabel += fRow;
   } else if (fType == kColumnHeader) {
      *fLabel += "Col ";
      *fLabel += fColumn;
   } else {
      *fLabel += fTable->GetNTableRows();
      *fLabel += "x";
      *fLabel += fTable->GetNTableColumns();
      *fLabel += " Table";
   }
}

//______________________________________________________________________________
void TGTableHeader::SetPosition(UInt_t pos)
{
   // Set the position of the TGTableHeader to pos.
   
   // Verify functionality

   if (fType == kRowHeader) {
      fRow = pos;
      fColumn = 0;
   } else if (fType == kColumnHeader) {
      fRow = 0;
      fColumn = pos;
   } else {
      fRow = 0;
      fColumn = 0;
   }
}

//______________________________________________________________________________
void TGTableHeader::Resize(TGDimension newsize)
{
   // Resize the TGTableHeader.

   Resize(newsize.fWidth, newsize.fHeight);
}

//______________________________________________________________________________
void TGTableHeader::Resize(UInt_t width, UInt_t height)
{
   // Resize the TGTableHeader.

   // Implementation of resizing of an entire row of columns probably goes here.
   TGTableCell::Resize(width, height);
}

//______________________________________________________________________________
void TGTableHeader::Sort(Bool_t order)
{
   // Sort the contents of this row or column in given order.

   // Note: not implemented yet.

   if (order == kSortAscending) {
   } else {
   }
}

//______________________________________________________________________________
void TGTableHeader::UpdatePosition()
{
   // Update the positon of the TGTableHeader.

   // Verify functionality. If rows are inserted or removed, internal
   // column numbers are no longer consistent.

   UInt_t nhdr = 0;
   if (fType == kColumnHeader) {
      while(fTable->GetColumnHeader(nhdr) != this) {
         nhdr++;
      }
      fColumn = nhdr;
   } else if (fType == kRowHeader) {
      while(fTable->GetRowHeader(nhdr) != this) {
         nhdr++;
      }
      fRow = nhdr;
   } else {
      fRow = 0;
      fColumn = 0;
   }
}
 TGTableHeader.cxx:1
 TGTableHeader.cxx:2
 TGTableHeader.cxx:3
 TGTableHeader.cxx:4
 TGTableHeader.cxx:5
 TGTableHeader.cxx:6
 TGTableHeader.cxx:7
 TGTableHeader.cxx:8
 TGTableHeader.cxx:9
 TGTableHeader.cxx:10
 TGTableHeader.cxx:11
 TGTableHeader.cxx:12
 TGTableHeader.cxx:13
 TGTableHeader.cxx:14
 TGTableHeader.cxx:15
 TGTableHeader.cxx:16
 TGTableHeader.cxx:17
 TGTableHeader.cxx:18
 TGTableHeader.cxx:19
 TGTableHeader.cxx:20
 TGTableHeader.cxx:21
 TGTableHeader.cxx:22
 TGTableHeader.cxx:23
 TGTableHeader.cxx:24
 TGTableHeader.cxx:25
 TGTableHeader.cxx:26
 TGTableHeader.cxx:27
 TGTableHeader.cxx:28
 TGTableHeader.cxx:29
 TGTableHeader.cxx:30
 TGTableHeader.cxx:31
 TGTableHeader.cxx:32
 TGTableHeader.cxx:33
 TGTableHeader.cxx:34
 TGTableHeader.cxx:35
 TGTableHeader.cxx:36
 TGTableHeader.cxx:37
 TGTableHeader.cxx:38
 TGTableHeader.cxx:39
 TGTableHeader.cxx:40
 TGTableHeader.cxx:41
 TGTableHeader.cxx:42
 TGTableHeader.cxx:43
 TGTableHeader.cxx:44
 TGTableHeader.cxx:45
 TGTableHeader.cxx:46
 TGTableHeader.cxx:47
 TGTableHeader.cxx:48
 TGTableHeader.cxx:49
 TGTableHeader.cxx:50
 TGTableHeader.cxx:51
 TGTableHeader.cxx:52
 TGTableHeader.cxx:53
 TGTableHeader.cxx:54
 TGTableHeader.cxx:55
 TGTableHeader.cxx:56
 TGTableHeader.cxx:57
 TGTableHeader.cxx:58
 TGTableHeader.cxx:59
 TGTableHeader.cxx:60
 TGTableHeader.cxx:61
 TGTableHeader.cxx:62
 TGTableHeader.cxx:63
 TGTableHeader.cxx:64
 TGTableHeader.cxx:65
 TGTableHeader.cxx:66
 TGTableHeader.cxx:67
 TGTableHeader.cxx:68
 TGTableHeader.cxx:69
 TGTableHeader.cxx:70
 TGTableHeader.cxx:71
 TGTableHeader.cxx:72
 TGTableHeader.cxx:73
 TGTableHeader.cxx:74
 TGTableHeader.cxx:75
 TGTableHeader.cxx:76
 TGTableHeader.cxx:77
 TGTableHeader.cxx:78
 TGTableHeader.cxx:79
 TGTableHeader.cxx:80
 TGTableHeader.cxx:81
 TGTableHeader.cxx:82
 TGTableHeader.cxx:83
 TGTableHeader.cxx:84
 TGTableHeader.cxx:85
 TGTableHeader.cxx:86
 TGTableHeader.cxx:87
 TGTableHeader.cxx:88
 TGTableHeader.cxx:89
 TGTableHeader.cxx:90
 TGTableHeader.cxx:91
 TGTableHeader.cxx:92
 TGTableHeader.cxx:93
 TGTableHeader.cxx:94
 TGTableHeader.cxx:95
 TGTableHeader.cxx:96
 TGTableHeader.cxx:97
 TGTableHeader.cxx:98
 TGTableHeader.cxx:99
 TGTableHeader.cxx:100
 TGTableHeader.cxx:101
 TGTableHeader.cxx:102
 TGTableHeader.cxx:103
 TGTableHeader.cxx:104
 TGTableHeader.cxx:105
 TGTableHeader.cxx:106
 TGTableHeader.cxx:107
 TGTableHeader.cxx:108
 TGTableHeader.cxx:109
 TGTableHeader.cxx:110
 TGTableHeader.cxx:111
 TGTableHeader.cxx:112
 TGTableHeader.cxx:113
 TGTableHeader.cxx:114
 TGTableHeader.cxx:115
 TGTableHeader.cxx:116
 TGTableHeader.cxx:117
 TGTableHeader.cxx:118
 TGTableHeader.cxx:119
 TGTableHeader.cxx:120
 TGTableHeader.cxx:121
 TGTableHeader.cxx:122
 TGTableHeader.cxx:123
 TGTableHeader.cxx:124
 TGTableHeader.cxx:125
 TGTableHeader.cxx:126
 TGTableHeader.cxx:127
 TGTableHeader.cxx:128
 TGTableHeader.cxx:129
 TGTableHeader.cxx:130
 TGTableHeader.cxx:131
 TGTableHeader.cxx:132
 TGTableHeader.cxx:133
 TGTableHeader.cxx:134
 TGTableHeader.cxx:135
 TGTableHeader.cxx:136
 TGTableHeader.cxx:137
 TGTableHeader.cxx:138
 TGTableHeader.cxx:139
 TGTableHeader.cxx:140
 TGTableHeader.cxx:141
 TGTableHeader.cxx:142
 TGTableHeader.cxx:143
 TGTableHeader.cxx:144
 TGTableHeader.cxx:145
 TGTableHeader.cxx:146
 TGTableHeader.cxx:147
 TGTableHeader.cxx:148
 TGTableHeader.cxx:149
 TGTableHeader.cxx:150
 TGTableHeader.cxx:151
 TGTableHeader.cxx:152
 TGTableHeader.cxx:153
 TGTableHeader.cxx:154
 TGTableHeader.cxx:155
 TGTableHeader.cxx:156
 TGTableHeader.cxx:157
 TGTableHeader.cxx:158
 TGTableHeader.cxx:159
 TGTableHeader.cxx:160
 TGTableHeader.cxx:161
 TGTableHeader.cxx:162
 TGTableHeader.cxx:163
 TGTableHeader.cxx:164
 TGTableHeader.cxx:165
 TGTableHeader.cxx:166
 TGTableHeader.cxx:167
 TGTableHeader.cxx:168
 TGTableHeader.cxx:169
 TGTableHeader.cxx:170
 TGTableHeader.cxx:171
 TGTableHeader.cxx:172
 TGTableHeader.cxx:173
 TGTableHeader.cxx:174
 TGTableHeader.cxx:175
 TGTableHeader.cxx:176
 TGTableHeader.cxx:177
 TGTableHeader.cxx:178
 TGTableHeader.cxx:179
 TGTableHeader.cxx:180
 TGTableHeader.cxx:181
 TGTableHeader.cxx:182
 TGTableHeader.cxx:183
 TGTableHeader.cxx:184
 TGTableHeader.cxx:185
 TGTableHeader.cxx:186
 TGTableHeader.cxx:187
 TGTableHeader.cxx:188
 TGTableHeader.cxx:189
 TGTableHeader.cxx:190
 TGTableHeader.cxx:191
 TGTableHeader.cxx:192
 TGTableHeader.cxx:193
 TGTableHeader.cxx:194
 TGTableHeader.cxx:195
 TGTableHeader.cxx:196
 TGTableHeader.cxx:197
 TGTableHeader.cxx:198
 TGTableHeader.cxx:199
 TGTableHeader.cxx:200
 TGTableHeader.cxx:201
 TGTableHeader.cxx:202
 TGTableHeader.cxx:203
 TGTableHeader.cxx:204
 TGTableHeader.cxx:205
 TGTableHeader.cxx:206
 TGTableHeader.cxx:207
 TGTableHeader.cxx:208
 TGTableHeader.cxx:209
 TGTableHeader.cxx:210
 TGTableHeader.cxx:211
 TGTableHeader.cxx:212
 TGTableHeader.cxx:213
 TGTableHeader.cxx:214
 TGTableHeader.cxx:215
 TGTableHeader.cxx:216
 TGTableHeader.cxx:217
 TGTableHeader.cxx:218
 TGTableHeader.cxx:219
 TGTableHeader.cxx:220
 TGTableHeader.cxx:221
 TGTableHeader.cxx:222
 TGTableHeader.cxx:223
 TGTableHeader.cxx:224
 TGTableHeader.cxx:225
 TGTableHeader.cxx:226
 TGTableHeader.cxx:227
 TGTableHeader.cxx:228
 TGTableHeader.cxx:229
 TGTableHeader.cxx:230
 TGTableHeader.cxx:231
 TGTableHeader.cxx:232
 TGTableHeader.cxx:233
 TGTableHeader.cxx:234
 TGTableHeader.cxx:235
 TGTableHeader.cxx:236
 TGTableHeader.cxx:237
 TGTableHeader.cxx:238
 TGTableHeader.cxx:239
 TGTableHeader.cxx:240
 TGTableHeader.cxx:241
 TGTableHeader.cxx:242
 TGTableHeader.cxx:243
 TGTableHeader.cxx:244
 TGTableHeader.cxx:245
 TGTableHeader.cxx:246
 TGTableHeader.cxx:247
 TGTableHeader.cxx:248
 TGTableHeader.cxx:249
 TGTableHeader.cxx:250
 TGTableHeader.cxx:251
 TGTableHeader.cxx:252
 TGTableHeader.cxx:253
 TGTableHeader.cxx:254
 TGTableHeader.cxx:255
 TGTableHeader.cxx:256
 TGTableHeader.cxx:257
 TGTableHeader.cxx:258
 TGTableHeader.cxx:259