home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CDateView.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.9 KB  |  191 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. #ifndef __H_CDateView
  20. #define __H_CDateView
  21. #pragma once
  22.  
  23. /*======================================================================================
  24.  
  25.     DESCRIPTION:    Implements a view for display and input of a date. Formats the date
  26.                     as the user has it set up in their Date & Time control panel.
  27.                     
  28.                     To use this class, you must include the following PP classes:
  29.                     
  30.                         LGAEditField
  31.                         LCaption
  32.                         LButton
  33.  
  34.     MODIFICATIONS:
  35.  
  36.     Date            Person            Description
  37.     ----            ------            -----------
  38. ======================================================================================*/
  39.  
  40.  
  41. /*====================================================================================*/
  42.     #pragma mark INCLUDE FILES
  43. /*====================================================================================*/
  44.  
  45. #include <LView.h>
  46. #include <LListener.h>
  47. #include <LGAEditField.h>
  48.  
  49. class CDateField;
  50.  
  51.  
  52. /*====================================================================================*/
  53.     #pragma mark TYPEDEFS
  54. /*====================================================================================*/
  55.  
  56.  
  57. /*====================================================================================*/
  58.     #pragma mark CONSTANTS
  59. /*====================================================================================*/
  60.  
  61.  
  62. /*====================================================================================*/
  63.     #pragma mark CLASS DECLARATIONS
  64. /*====================================================================================*/
  65.  
  66. #pragma mark -
  67.  
  68. class CDateView : public LView,
  69.                   public LListener,
  70.                   public LBroadcaster {
  71.                   
  72. public:
  73.  
  74.     enum {    // Pane IDs
  75.         paneID_DateField1 = 'DAT1'
  76.     ,    paneID_DateField2 = 'DAT2'
  77.     ,    paneID_DateField3 = 'DAT3'
  78.     ,    paneID_Separator1 = 'SEP1'
  79.     ,    paneID_Separator2 = 'SEP2'
  80.     ,    paneID_UpButton =     'BTNU'
  81.     ,    paneID_DownButton = 'BTND'
  82.     };
  83.  
  84.     // Stream creator method
  85.  
  86.     enum { class_ID = 'DaTe' };
  87.     static void            RegisterDateClasses(void);
  88.  
  89.                         CDateView(LStream *inStream);
  90.     virtual                ~CDateView(void);
  91.     
  92.     // Start public interface ----------------------------------------------------------
  93.  
  94.     enum { cMinViewYear = 1920, cMaxViewYear = 2019 };
  95.  
  96.     Boolean                IsValidDate(Int16 inYear, UInt8 inMonth, UInt8 inDay);
  97.     void                GetDate(Int16 *outYear, UInt8 *outMonth, UInt8 *outDay);
  98.  
  99.     Boolean                SetDate(Int16 inYear, UInt8 inMonth, UInt8 inDay);
  100.     void                SetToToday(void);
  101.  
  102.     enum { eYearField = 1, eMonthField = 2, eDayField = 3 };
  103.     void                SelectDateField(Int16 inField);
  104.     void                Select(void);
  105.  
  106.     Boolean                ContainsTarget(void);
  107.     
  108.     // Boradcasting messages
  109.     enum { msg_DateViewChanged = 9109221 /*this*/ };
  110.  
  111.     // End public interface ------------------------------------------------------------
  112.  
  113. protected:
  114.  
  115.     // Overriden methods
  116.  
  117.     virtual void        FinishCreateSelf(void);
  118.     virtual void        ListenToMessage(MessageT inMessage, void *ioParam = nil);
  119.     
  120.     void                DoKeyArrow(Boolean inClickUpArrow);
  121.     void                DoClickArrow(Boolean inClickUpArrow);
  122.  
  123.     enum { eShowArrows = true, eHideArrows = false };
  124.     void                ShowHideArrows(Boolean inShow);
  125.  
  126.     // static EKeyStatus    DateFieldFilter(const EventRecord &inKeyEvent, Int16 inKeyPosition = 0);
  127.     static EKeyStatus    DateFieldFilter(TEHandle inMacTEH, Char16 inKeyCode, Char16& ioCharCode, SInt16 inModifiers);
  128.     static void            SetDateString(LEditField *inField, UInt8 inValue, UInt8 inLeadingChar);
  129.     static void            ShowHideArrow(LPane *inArrow, Boolean inShow);
  130.  
  131. private:
  132.  
  133.     void                CreateDateFields(UInt8 inLeadingDayChar, UInt8 inLeadingMonthChar, 
  134.                                           UInt8 inSeparatingChar);
  135.  
  136. protected:
  137.  
  138.     // Instance variables ==========================================================
  139.     
  140.     UInt8                mDayPosition;        // Position of the day in the view (1..3)
  141.     UInt8                mMonthPosition;        // Position of the month in the view (1..3)
  142.     UInt8                mYearPosition;        // Position of the year in the view (1..3)
  143.     
  144.     Rect                 mFrameRect;
  145.     
  146.     CDateField            *mDayField;
  147.     CDateField            *mMonthField;
  148.     CDateField            *mYearField;
  149. };
  150.  
  151.  
  152. #pragma mark -
  153.  
  154. class CDateField : public LGAEditField {
  155.  
  156. public:
  157.  
  158.     enum { class_ID = 'DaFd' };
  159.                         CDateField(LStream *inStream);
  160.  
  161.     virtual void        SetDescriptor(ConstStr255Param inDescriptor);
  162.     UInt8                GetLeadingChar(void) const { return mLeadingChar; }
  163.     void                SetLeadingChar(UInt8 inChar) { mLeadingChar = inChar; }
  164.     
  165.     // Boradcasting messages
  166.     enum { msg_HideDateArrows = 780954, msg_ShowDateArrows = 780955,
  167.            msg_UserChangedText = 780956 };
  168.  
  169. protected:
  170.  
  171.     // Overriden methods
  172.  
  173.     virtual void        ClickSelf(const SMouseDownEvent &inMouseDown);
  174.     virtual void        FindCommandStatus(CommandT    inCommand, Boolean &outEnabled,
  175.                                             Boolean &outUsesMark, Char16 &outMark,
  176.                                              Str255 outName);
  177.     virtual Boolean        HandleKeyPress(const EventRecord &inKeyEvent);
  178.     virtual void        AdjustCursorSelf(Point inPortPt, const EventRecord &inMacEvent);
  179.  
  180.     virtual void        BeTarget(void);
  181.     virtual void        DontBeTarget(void);
  182.  
  183.     virtual void        UserChangedText(void);
  184.  
  185.     // Instance variables ==========================================================
  186.     
  187.     UInt8                mLeadingChar;        // Character to use for leading number when
  188. };
  189.  
  190. #endif // __H_CDateView
  191.