home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / rdfui / CHyperTreeHeader.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  3.6 KB  |  120 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "CHyperTreeHeader.h"
  20.  
  21. #include <LString.h>
  22. #include <LCaption.h>
  23.  
  24. CHyperTreeHeader::CHyperTreeHeader(LStream* inStream)
  25. :    CTriStateTableHeader(inStream)
  26. {
  27. }
  28.  
  29. CHyperTreeHeader::~CHyperTreeHeader()
  30. {
  31. }
  32.  
  33. void
  34. CHyperTreeHeader::SetUpColumns(HT_Cursor columnCursor)
  35. {
  36.     LTableHeader::SColumnData columnData;
  37.     ColumnInfo columnInfo;
  38.     PaneIDT columnPaneID = 1;
  39.     void *columnToken;
  40.     Uint32 columnWidth, columnTokenType;
  41.     SPaneInfo paneInfo;
  42.     char *columnName;
  43.     vector<LTableHeader::SColumnData> dataVector;
  44.  
  45.     // initialize SPaneInfo fields that don't change
  46.     paneInfo.width =     50;
  47.     paneInfo.height =     12;
  48.     paneInfo.visible =    false;
  49.     paneInfo.enabled =    false;
  50.     paneInfo.bindings.left = false;
  51.     paneInfo.bindings.top = false;
  52.     paneInfo.bindings.right = false;
  53.     paneInfo.bindings.bottom = false;
  54.     paneInfo.left =        0;
  55.     paneInfo.top =        0;
  56.     paneInfo.userCon =    NULL;
  57.     paneInfo.superView = this;
  58.  
  59.     DeleteAllSubPanes();
  60.  
  61.     // initialize LTableHeader::SColumnData fields that don't change    
  62.     columnData.columnPosition = 0;
  63.     columnData.flags = 0;
  64.  
  65.     // get column data from cursor
  66.     while (HT_GetNextColumn(columnCursor, &columnName, &columnWidth, &columnToken, &columnTokenType))
  67.     {
  68.         LStr255 name(columnName);
  69.         
  70.         paneInfo.paneID =    columnPaneID;
  71.         
  72.         LCaption* columnCaption = new LCaption(paneInfo, name, columnTextTraits_ID);
  73.         
  74.         columnData.paneID = columnPaneID;
  75.         columnData.columnWidth = columnWidth;
  76.         
  77.         dataVector.push_back(columnData);
  78.         
  79.         columnInfo.token = columnToken;
  80.         columnInfo.tokenType = columnTokenType;
  81.         
  82.         mColumnInfo.push_back(columnInfo);
  83.         
  84.         columnCaption->Enable();
  85.         columnCaption->Show();
  86.         
  87.         ++columnPaneID;
  88.     }
  89.     
  90.     // LTableHeader expects its mColumnData member to be a mac Handle;
  91.     // therefore, create the Handle from dataVector.
  92.     Handle handle = ::NewHandle(sizeof(LTableHeader::SColumnData) * dataVector.size());
  93.     // I have no clue who is going to catch this, but if we can't allocate the
  94.     // Handle, we're up the creek without a paddle and with a very leaky canoe.
  95.     ThrowIfMemFail_(handle);
  96.     LHandleStream dataStream(handle);
  97.     vector<LTableHeader::SColumnData>::iterator iter = dataVector.begin();
  98.     while (iter != dataVector.end())
  99.     {
  100.         Int32 byteCount = sizeof(LTableHeader::SColumnData);
  101.         dataStream.PutBytes(iter, byteCount);
  102.         ++iter;
  103.     }
  104.     if (mColumnData)
  105.         ::DisposeHandle(reinterpret_cast<Handle>(mColumnData));
  106.     mColumnData = reinterpret_cast<LTableHeader::SColumnData**>(dataStream.DetachDataHandle());
  107.     // now initialize LTableHeader data members and have it sync itself up
  108.     mColumnCount = dataVector.size();
  109.     mLastVisibleColumn = mColumnCount;
  110.     ConvertWidthsToAbsolute();
  111.     ComputeColumnPositions();
  112.     PositionColumnHeaders(true);
  113. }
  114.  
  115. CHyperTreeHeader::ColumnInfo&
  116. CHyperTreeHeader::GetColumnInfo(Uint32 inColumnKey)
  117. {
  118.     vector<ColumnInfo>::iterator iter = mColumnInfo.begin();
  119.     return *(iter + inColumnKey);
  120. }