home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / Tables / CSingleTextColumn.cp next >
Encoding:
Text File  |  1998-04-08  |  4.4 KB  |  142 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. ///////////////////////////////////////////////////////////////////////////////////////
  20. //
  21. //    Who            When        What
  22. //    ---            ----        ----
  23. //    
  24. //    piro        12/1/97        Finished first implementation
  25. //
  26. ///////////////////////////////////////////////////////////////////////////////////////
  27.  
  28. #include "CSingleTextColumn.h"
  29. #include <LStream.h>
  30. #include <LTableMonoGeometry.h>
  31. #include <LTableSingleSelector.h>
  32. #include <LTableArrayStorage.h>
  33. #include <UDrawingUtils.h>
  34. #include <UTextTraits.h>
  35. #include <UGAColorRamp.h>
  36.  
  37. ///////////////////////////////////////////////////////////////////////////////////////
  38. // Constants
  39.  
  40. const MessageT    kDoubleClickMsg = 'chED';
  41. const short        kColWidth = 100;
  42. const short        kRowHeight = 16;
  43. const short        kStringSize = 256;
  44. const short        kSubtractToFitInScroller = 2;
  45.  
  46. ///////////////////////////////////////////////////////////////////////////////////////
  47. // Implementation
  48.  
  49. ///////////////////////////////////////////////////////////////////////////////////////
  50. // CSingleTextColumn
  51. CSingleTextColumn::CSingleTextColumn( LStream *inStream)
  52.     : LTableView(inStream), mTxtrID( 0 )
  53. {
  54.     *inStream >> mTxtrID;
  55.     InitSingleTextColumn();
  56. }
  57.  
  58. ///////////////////////////////////////////////////////////////////////////////////////
  59. // ~CSingleTextColumn
  60. CSingleTextColumn::~CSingleTextColumn()
  61. {
  62. }
  63.  
  64. ///////////////////////////////////////////////////////////////////////////////////////
  65. // InitSingleTextColumn()
  66. void
  67. CSingleTextColumn::InitSingleTextColumn()
  68. {
  69.     // single size geometry
  70.     SetTableGeometry(new LTableMonoGeometry(this, mFrameSize.width - kSubtractToFitInScroller, kRowHeight));
  71.  
  72.     // single selection
  73.     SetTableSelector(new LTableSingleSelector(this));
  74.     
  75.     // storage
  76.     SetTableStorage( new LTableArrayStorage( this, (unsigned long) 0 ) );
  77.  
  78.     LTableView::InsertCols(1, 0, nil, 0, Refresh_No);
  79. }
  80.  
  81. ///////////////////////////////////////////////////////////////////////////////////////
  82. // ClickCell( const STableCell& inCell, const SMouseDownEvent& inMouseDown )
  83. void         
  84. CSingleTextColumn::ClickCell( const STableCell&, const SMouseDownEvent& )
  85. {
  86.     if ( GetClickCount() == 1 ) // single click
  87.     {
  88.         FocusDraw();
  89.     }
  90.     else if ( GetClickCount() == 2 ) // double click
  91.     {
  92.         BroadcastMessage( msg_SingleTextColumnDoubleClick, static_cast<void*>( this ) );
  93.     }
  94. }
  95.  
  96. ///////////////////////////////////////////////////////////////////////////////////////
  97. // ClickCell( const STableCell& inCell, const SMouseDownEvent& inMouseDown )
  98. void
  99. CSingleTextColumn::DrawCell( const STableCell &inCell, const Rect &inLocalRect)
  100. {
  101.     Rect    textRect = inLocalRect;
  102.     ::InsetRect(&textRect, 2, 0);
  103.     
  104.     Str255    str;
  105.     Uint32    len = sizeof(str);
  106.     GetCellData(inCell, str, len);
  107.     
  108.     Int16    just = UTextTraits::SetPortTextTraits(mTxtrID);
  109.     UTextDrawing::DrawWithJustification((Ptr) str + 1, str[0], textRect, just);
  110. }
  111.  
  112. ///////////////////////////////////////////////////////////////////////////////////////
  113. // ClickSelf( const SMouseDownEvent&    inMouseDown )
  114. void
  115. CSingleTextColumn::ClickSelf( const SMouseDownEvent&    inMouseDown )
  116. {
  117.     STableCell    hitCell;
  118.     SPoint32    imagePt;
  119.     
  120.     LocalToImagePoint(inMouseDown.whereLocal, imagePt);
  121.     if ( GetCellHitBy( imagePt, hitCell ) )
  122.             LTableView::ClickSelf( inMouseDown );
  123. }
  124.  
  125. ///////////////////////////////////////////////////////////////////////////////////////
  126. // DrawSelf()
  127. void
  128. CSingleTextColumn::DrawSelf()
  129. {
  130.     RgnHandle localUpdateRgnH = GetLocalUpdateRgn();
  131.     Rect updateRect = (**localUpdateRgnH).rgnBBox;
  132.     DisposeRgn(localUpdateRgnH);
  133.     
  134.     {
  135.         StColorState saveTheColor;
  136.         RGBBackColor( &( UGAColorRamp::GetWhiteColor() ) );
  137.         EraseRect(&updateRect);
  138.     }
  139.     
  140.     LTableView::DrawSelf();
  141. }
  142.