home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / macgui.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  11.0 KB  |  327 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. #pragma once
  20. /*
  21.     GUI Library
  22.     Classes for customizing the GUI of a program. There are subclasses of
  23.     various PowerPlant classes in lieu of a more dynamic mechanism
  24.     CS
  25.     Color Scheme Library
  26. */
  27. #include <LTextEdit.h>
  28. #include <LGAEditField.h>
  29. #include "CFontReference.h"
  30. //#include "VEditField.h"
  31. #include "CTSMEditField.h"
  32. #include "uprefd.h"
  33. #include "xp_hash.h"
  34. #include "lo_ele.h"
  35. #include <LPicture.h>
  36.  
  37. typedef struct LO_TextAttr_struct LO_TextAttr;
  38.  
  39. /*******************************************************************************
  40.  * StPrepareForDialog is a simple class that ensures application is in the
  41.  * foreground, and desktop deactivated.
  42.  * Insert into functions that will open Toolbox dialog boxes.
  43.  * Used only for side-effects
  44.  *******************************************************************************/
  45. class StPrepareForDialog
  46. {
  47. public:
  48.     StPrepareForDialog();
  49.     ~StPrepareForDialog();
  50. };
  51.  
  52.  
  53. /*-----------------------------------------------------------------------------
  54.     UGraphics is full of little graphics utilities
  55. -----------------------------------------------------------------------------*/
  56. class UGraphics
  57. {
  58. public:
  59.  
  60.     // Note, the numbering of these enums is reflected in pref.r
  61.     // Be sure to reflect changes there as well
  62.     static void     Initialize();
  63.     
  64.     static const RGBColor&    Get( CPrefs::PrefEnum r );
  65.     static void             SetFore( CPrefs::PrefEnum r );
  66.     static void             SetBack( CPrefs::PrefEnum r );
  67.     static inline void        SetIfColor( const RGBColor& color ); // Use instead of RGBForeColor
  68.     static inline void        SetIfBkColor( const RGBColor& color );    // Use instead of RGBBackColor -- optimized
  69.     static inline Boolean    EqualColor( const RGBColor& c1, const RGBColor& c2 );
  70.     static inline RGBColor    MakeRGBColor( UInt8 red, UInt8 green, UInt8 blue );
  71.     static inline RGBColor    MakeRGBColor( LO_Color color );
  72.     static inline LO_Color    MakeLOColor(const RGBColor& color);
  73.     static void             VertLine( int x, int top, int height, CPrefs::PrefEnum r );
  74.     static void             HorizLineAtWidth( int vertical, int left, int width, 
  75.                                 CPrefs::PrefEnum r );
  76.     static CGrafPtr            IsColorPort( GrafPtr port );            // TRUE if GrafPtr is a color port
  77.     static void                SetWindowColors( LWindow *window );
  78.     static void                SetWindowColor( GrafPort *window, short field, const RGBColor& color );
  79.  
  80.  
  81.     static void                DrawLine( Int16 top, Int16 left, Int16 bottom, Int16 right,
  82.                                 CPrefs::PrefEnum color );
  83.     static void                FrameRectMotif( const Rect& box, Boolean inset );
  84.     static void                FrameRectSubtle (const Rect& box, Boolean inset);
  85.     static void                FrameRectBevel (const Rect& box, Boolean inset, const RGBColor &lighter, const RGBColor &darker );
  86.     static void                FrameTopLeftShaded( const Rect& box, short width, const RGBColor& curr );
  87.     static void                FrameRectShaded( const Rect& box, Boolean inset );
  88.     static void                FrameEraseRect(const Rect& box, short width, Boolean focussed);    // Erases rect in background patterns
  89.     static void                DarkenRect(const Rect & box);
  90.     // Used in pane calculations
  91.     static Boolean            PointInBigRect( SPoint32 rectLoc, SDimension16 rectSize, SPoint32 loc );
  92.     static void                FrameCircleShaded( const Rect& box, Boolean inset );
  93.     
  94.     static RgnHandle        GetTempRegion();                    // Get a region for a while
  95.     static void                ReleaseTempRegion(RgnHandle rgn);    // Return the region to the pile
  96.  
  97. private:
  98.     enum { kRegionCacheSize = 5 };                                // If you change this constant, change the static array initializer in macgui.c!
  99.     static RgnHandle        sTempRegions[kRegionCacheSize];        // Cached regions for use by UGraphics:GetTempRegion
  100.     static Boolean            sRegionsUsed[kRegionCacheSize];        // Which cached regions are in use?
  101. };
  102.  
  103. inline Boolean UGraphics::EqualColor( const RGBColor& c1, const RGBColor& c2 )
  104. {
  105.     return ((c1.red == c2.red) && (c1.green == c2.green) && (c1.blue == c2.blue));
  106. }
  107.  
  108. inline void UGraphics::SetIfColor( const RGBColor& newColor )
  109. {
  110.     RGBColor currentColor = ((CGrafPtr)qd.thePort)->rgbFgColor;
  111.     if ( !EqualColor( currentColor, newColor ) )
  112.         ::RGBForeColor( &newColor );
  113. }
  114.  
  115. inline void UGraphics::SetIfBkColor( const RGBColor& newColor )
  116. {
  117.     CGrafPtr cgp = (CGrafPtr)qd.thePort;
  118.     RGBColor currentColor = cgp->rgbBkColor;
  119.     if ( !EqualColor( currentColor, newColor ) )
  120.         ::RGBBackColor( &newColor );
  121. }
  122.  
  123. inline RGBColor UGraphics::MakeRGBColor( UInt8 red, UInt8 green, UInt8 blue )
  124. {
  125.     RGBColor        temp;
  126.     temp.red    = (red   == 255 ? 65535 : (((unsigned short)red) << 8));
  127.     temp.green    = (green == 255 ? 65535 : (((unsigned short)green) << 8));
  128.     temp.blue    = (blue  == 255 ? 65535 : (((unsigned short)blue) << 8));
  129.     return temp;
  130. }
  131.  
  132. inline RGBColor UGraphics::MakeRGBColor( LO_Color color )
  133. {
  134.     RGBColor        temp;
  135.     temp.red    = (color.red   == 255 ? 65535 : (((unsigned short)color.red) << 8));
  136.     temp.green    = (color.green == 255 ? 65535 : (((unsigned short)color.green) << 8));
  137.     temp.blue    = (color.blue  == 255 ? 65535 : (((unsigned short)color.blue) << 8));
  138.     return temp;
  139. }
  140.  
  141. inline LO_Color UGraphics::MakeLOColor(const RGBColor& color )
  142. {
  143.     LO_Color        temp;
  144.     temp.red    = (((unsigned short)color.red) >> 8);
  145.     temp.green    = (((unsigned short)color.green) >> 8);
  146.     temp.blue    = (((unsigned short)color.blue) >> 8);
  147.     return temp;
  148. }
  149.  
  150.  
  151. /*-----------------------------------------------------------------------------
  152.     HyperStyle is a Mac-oriented style sheet. It is produced once we've
  153.     done all the mapping from HTML. It keeps things in native format, so
  154.     even though Color comes from a restricted set, it's in here as RGB,
  155.     and Strikethrough, logically a style, is kept out of the style field.
  156.     The goal is to make setting text attributes fast. Creating them can
  157.     be done via a caching table.
  158. -----------------------------------------------------------------------------*/
  159. class HyperStyle
  160. {
  161. public:
  162.     static void        InitHyperStyle();
  163.     static void        FinishHyperStyle();
  164. /*
  165.                     HyperStyle( HyperStyle * s );
  166. */
  167.                     HyperStyle( MWContext *context,
  168.                             const CCharSet* charSet, 
  169.                             LO_TextAttr* attr,
  170.                             Boolean onlyMeasuring = FALSE,
  171.                             LO_TextStruct* element = NULL );
  172. /*
  173.                     ~HyperStyle() { if (fFontReference) delete fFontReference; }
  174. */
  175.  
  176.     Rect            InvalBackground( Point where, char* text,
  177.                             int start,
  178.                             int end, Boolean blinks );
  179.                             
  180.     inline void     Apply();
  181.     void            GetFontInfo();
  182.  
  183.                     // draw text using these attributes
  184.     void            DrawText(    Point where,
  185.                                 char* text,
  186.                                 int start,
  187.                                 int end );
  188.  
  189.     short            TextWidth(    char* text, 
  190.                                 int firstByte, 
  191.                                 int byteCount);
  192.     
  193.     // Actual style elements
  194.     CFontReference    *fFontReference;
  195.     RGBColor        rgbFgColor;
  196.     RGBColor        rgbBkColor;
  197.     Boolean            strike;
  198.     Int32            fInlineInput;
  199.     LO_TextStruct*    fElement;
  200.     Boolean            fOnlyMeasuring;
  201.  
  202. // Font info hashing stuff
  203.     FontInfo        fFontInfo;
  204. private:
  205.     LO_TextAttr        fAttr;
  206.         
  207.         // save/restore the pen and text state to be a good neighbor
  208.     StColorPenState fSavedPen;
  209.     StTextState        fSavedText;
  210.  
  211.     static XP_HashTable    sFontHash;
  212.     static Boolean    sUnderlineLinks;
  213.     static int        SetUnderlineLinks(const char * newpref, void * stuff);
  214.     static uint32    StyleHash( const void* hyperStyle );
  215.     static int        StyleCompFunction( const void* style1, const void* style2 );
  216. };
  217.  
  218. inline void HyperStyle::Apply()
  219. {
  220.     fFontReference->Apply();
  221.     UGraphics::SetIfColor( rgbFgColor );
  222.     UGraphics::SetIfBkColor( rgbBkColor );
  223. }
  224.  
  225.  
  226.  
  227. /*****************************************************************************
  228.  * class CCoolBackground
  229.  * Sets up the background color for drawing chrome in the main window
  230.  * It is either gray, or utility pattern, depending upon your preferences
  231.  ****************************************************************************/
  232. class CCoolBackground
  233. {
  234. private:
  235.     static PixPatHandle sPixPat;
  236.     PixPatHandle fOldPixPat;
  237. public:
  238.     CCoolBackground();
  239.     virtual ~CCoolBackground();
  240. };
  241.  
  242. const MessageT msg_EditField = 2002;    // Edit field has been modified
  243.  
  244. /*****************************************************************************
  245.  * class CEditBroadcaster
  246.  * CTSMEditField that notifies listeners about its changes
  247.  *****************************************************************************/
  248. class CEditBroadcaster    : public CTSMEditField, public LBroadcaster
  249. {
  250. public:
  251.  
  252.     // ÑÑ Constructors/destructors
  253.     enum { class_ID = 'ebro' };
  254.     CEditBroadcaster(LStream *inStream);
  255.  
  256.     // ÑÑ Misc
  257.     // Broadcast
  258.     void UserChangedText();
  259. };
  260.  
  261. /*****************************************************************************
  262.  * class CGAEditBroadcaster
  263.  * LGAEditField that notifies listeners about its changes
  264.  *****************************************************************************/
  265. class CGAEditBroadcaster    : public LGAEditField
  266. {
  267. public:
  268.  
  269.     // ÑÑ Constructors/destructors
  270.     enum { class_ID = 'Gebr' };
  271.     CGAEditBroadcaster(LStream *inStream);
  272.  
  273.     // ÑÑ Misc
  274.     // Broadcast
  275.     void BroadcastValueMessage();
  276.     void UserChangedText();
  277. };
  278.  
  279. /*****************************************************************************
  280.  * class CTextEdit
  281.  * LTextEdit, keeps track if it has been modified
  282.  *****************************************************************************/
  283. class CTextEdit    : public LTextEdit, public LBroadcaster
  284. {
  285.     Boolean fModified;        // Has user modified this field
  286. public:
  287.  
  288.     // ÑÑ Constructors/destructors
  289.     enum { class_ID = 'etxt' };
  290.     CTextEdit(LStream *inStream);
  291.     
  292.     // ÑÑ Misc
  293.     Boolean    IsModified(){return fModified;};
  294.     virtual void UserChangedText();
  295. };
  296.  
  297. /*****************************************************************************
  298.  * class CResPicture
  299.  * LPicture with an associated resfile ID
  300.  *****************************************************************************/
  301. class CResPicture : public LPicture
  302. {
  303. public:
  304.     enum { class_ID = 'rpic' };
  305.                     CResPicture(LStream *inStream);
  306.                     
  307.     virtual void    DrawSelf();
  308.     void            SetResFileID(short id) { mResFileID = id; };
  309.  
  310. private:
  311.     Int16            mResFileID;
  312. };
  313.  
  314. /******************************************************************************
  315.  * class StTempClipRgn
  316.  *    creates a temporary clip region. Old region is restored on exit
  317.  * CANNOT BE NESTED
  318.  *****************************************************************************/
  319. class StTempClipRgn
  320. {
  321.     static RgnHandle sOldClip;    // Saved clip    
  322.     static RgnHandle sMergedNewClip;    // New clip regions    
  323. public:
  324.     StTempClipRgn (RgnHandle newClip);
  325.     ~StTempClipRgn();
  326. };
  327.