home *** CD-ROM | disk | FTP | other *** search
/ MACD 7 / MACD7.iso / mui / mcc_datestring / developer / c / examples / datestring-demo.c
Encoding:
C/C++ Source or Header  |  1998-01-12  |  32.9 KB  |  858 lines

  1. /*
  2. **
  3. ** Copyright © 1996-1998 Kai Hofmann. All rights reserved.
  4. ** Registered MUI custom class!
  5. **
  6. ** $VER: DateString-Demo.c 12.3 (03.01.98)
  7. **
  8. */
  9.  
  10.  #define __MakeLib
  11.  
  12.  
  13.  #include "system.h"
  14.  #include <mui/Date_mcc.h>
  15.  #include <mui/DateString_mcc.h>
  16.  #include <mui/MonthNavigator_mcc.h>
  17.  #include <libraries/mui.h>
  18.  #include <proto/muimaster.h>
  19.  #include <proto/date.h>
  20.  #include <exec/libraries.h>
  21.  #include <exec/memory.h>
  22.  #include <proto/exec.h>
  23.  #include <proto/intuition.h>
  24.  #include <utility/tagitem.h>
  25.  #include <proto/utility.h>
  26.  #include <clib/alib_protos.h>
  27.  #include <string.h>
  28.  
  29.  
  30.  #ifdef DEBUG
  31.    void kprintf(UBYTE *fmt,...);
  32.    #define debug(x)    kprintf(x "\n");
  33.  #else
  34.    #define debug(x)
  35.  #endif
  36.  
  37.  
  38.  #ifndef MAKE_ID
  39.    #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  40.  #endif
  41.  
  42.  
  43.  struct MUI_CustomClass *App_CC=NULL,*Win_CC=NULL,*Str_CC=NULL,*DateNavigator_CC=NULL;
  44.  
  45.  
  46.  struct Library *DateBase;
  47.  struct Library *MUIMasterBase;
  48.  static Object *App;
  49.  
  50.  
  51.  #define MUIA_Group_Forward    0x80421422 /* V11 .s. BOOL */ /* private */
  52.  
  53.  #define MUIA_DateNavigator_ObjectID    ((TAG_USER | 494 << 16) | 0x8003)
  54.  #define MUIM_DateNavigator_Update    ((TAG_USER | 494 << 16) | 0x8004)
  55.  #define MUIM_DateNavigator_UpdateDay    ((TAG_USER | 494 << 16) | 0x8005)
  56.  #define MUIM_DateNavigator_MonthUpdate    ((TAG_USER | 494 << 16) | 0x8006)
  57.  
  58.  struct MUIP_DateNavigator_MonthUpdate    {ULONG MethodID; ULONG Month;};
  59.  
  60.  
  61.  struct DateNavigator_Data
  62.   {
  63.    Object *monthnavigator;
  64.    Object *month,*year,*day;
  65.   };
  66.  
  67.  
  68.  static char *months[13];
  69.  
  70.  /* ------------------------------------------------------------------------ */
  71.  
  72.  static ULONG STACKARGS DoSuperNew(struct IClass *const cl, Object *const obj, ULONG tags, ...)
  73.   {
  74.    return(DoSuperMethod(cl,obj,OM_NEW,&tags,NULL));
  75.   }
  76.  
  77.  /* --- String ------------------------------------------------------------- */
  78.  
  79.  static ULONG Str_New(struct IClass *cl, Object *obj, struct opSet *msg)
  80.   {
  81.    obj = (Object *)DoSuperNew(cl,obj,
  82.                               MUIA_String_Format,    MUIV_String_Format_Left,
  83.                               MUIA_String_MaxLen,    30,
  84.                               MUIA_Frame,        MUIV_Frame_String,
  85.                               MUIA_Background,        MUII_TextBack,
  86.                               TAG_MORE, msg->ops_AttrList
  87.                              );
  88.    return((ULONG)obj);
  89.   }
  90.  
  91.  
  92.  static ULONG Str_DragQuery(struct IClass *cl, Object *obj, struct MUIP_DragQuery *msg)
  93.   {
  94.    /*struct Str_Data *data = (struct Str_Data *)INST_DATA(cl,obj);*/
  95.    /*ULONG result;*/
  96.    ULONG Year,Month,Day;
  97.  
  98.    if (get(msg->obj,MUIA_Date_Year,&Year) && get(msg->obj,MUIA_Date_Month,&Month) && get(msg->obj,MUIA_Date_Day,&Day))
  99.     {
  100.      if (date_ValidHeisDate((unsigned short)Day,(unsigned short)Month,(long)Year))
  101.       {
  102.        return(MUIV_DragQuery_Accept);
  103.       }
  104.     }
  105.    return(MUIV_DragQuery_Refuse);
  106.   }
  107.  
  108.  
  109.  static ULONG Str_DragDrop(struct IClass *cl, Object *obj, struct MUIP_DragDrop *msg)
  110.   {
  111.    /*struct Str_Data *data = (struct Str_Data *)INST_DATA(cl,obj);*/
  112.    /*ULONG result;*/
  113.    char str[13];
  114.    ULONG Day,Month,Year;
  115.  
  116.    /*result =*/ get(msg->obj,MUIA_Date_Year,&Year);
  117.    /*result =*/ get(msg->obj,MUIA_Date_Month,&Month);
  118.    /*result =*/ get(msg->obj,MUIA_Date_Day,&Day);
  119.    date_FormatDate("%Y-%Dmv-%Ddv",(unsigned short)Day,(unsigned short)Month,(long)Year,date_Locale,str);
  120.    /*result =*/ set(obj,MUIA_String_Contents,(ULONG)str);
  121.    return(0);
  122.   }
  123.  
  124.  
  125.  static ULONG SAVEDS_ASM Str_Dispatcher(REG(A0) struct IClass *cl, REG(A2) Object *obj, REG(A1) Msg msg)
  126.   {
  127.    switch (msg->MethodID)
  128.     {
  129.      case OM_NEW            : return(Str_New(cl,obj,(struct opSet *)msg));
  130.      case MUIM_DragQuery        : return(Str_DragQuery(cl,obj,(struct MUIP_DragQuery *)msg));
  131.      case MUIM_DragDrop            : return(Str_DragDrop(cl,obj,(struct MUIP_DragDrop *)msg));
  132.      default                : return(DoSuperMethodA(cl,obj,msg));
  133.     }
  134.   }
  135.  
  136.  /* --- DateNavigator ------------------------------------------------------ */
  137.  
  138.  static ULONG DateNavigator_Update(struct IClass *cl, Object *obj, Msg msg)
  139.   {
  140.    struct DateNavigator_Data *data = (struct DateNavigator_Data *)INST_DATA(cl,obj);
  141.    ULONG year,month;
  142.  
  143.    /* Update the Monthnavigator with the new month/year values */
  144.    get(data->month,MUIA_Cycle_Active,&month);
  145.    month++;
  146.    get(data->year,MUIA_Numeric_Value,&year);
  147.    SetAttrs(data->monthnavigator,
  148.               MUIA_Date_Month,    month,
  149.               MUIA_Date_Year,    year,
  150.             TAG_DONE
  151.            );
  152.    /* set day to 0, because the user has not selected something within the new month/year */
  153.    if (data->day != NULL)
  154.     {
  155.      nnset(data->day,MUIA_Text_Contents,"0");
  156.     }
  157.    return(0);
  158.   }
  159.  
  160.  
  161.  static ULONG DateNavigator_UpdateDay(struct IClass *cl, Object *obj, Msg msg)
  162.   {
  163.    struct DateNavigator_Data *data = (struct DateNavigator_Data *)INST_DATA(cl,obj);
  164.    ULONG day;
  165.    char daystr[5];
  166.  
  167.    /* Update the text day object with MonthNavigators actual day */
  168.    get(data->monthnavigator,MUIA_Date_Day,&day);
  169.    date_FormatDate("%Ddv",(unsigned short)day,0,0,date_Locale,daystr);
  170.    nnset(data->day,MUIA_Text_Contents,daystr);
  171.    return(0);
  172.   }
  173.  
  174.  
  175.  static ULONG DateNavigator_MonthUpdate(struct IClass *cl, Object *obj, struct MUIP_DateNavigator_MonthUpdate *msg)
  176.   {
  177.    struct DateNavigator_Data *data = (struct DateNavigator_Data *)INST_DATA(cl,obj);
  178.    /*ULONG result;*/
  179.  
  180.    /* Update the month cycle gadget with MonthNavigators actual month */
  181.    nnset(data->month,MUIA_Cycle_Active,msg->Month-1);
  182.    return(0);
  183.   }
  184.  
  185.  
  186.  static ULONG DateNavigator_NoNotifySet(struct IClass *cl, Object *obj, struct MUIP_NoNotifySet *msg)
  187.   {
  188.    struct DateNavigator_Data *data = (struct DateNavigator_Data *)INST_DATA(cl,obj);
  189.    /*ULONG result;*/
  190.  
  191.    switch (msg->attr)
  192.     {
  193.      case MUIA_Date_Month    : nnset(data->month,MUIA_Cycle_Active,msg->val-1);
  194.                                   break;
  195.      case MUIA_Date_Year    : nnset(data->year,MUIA_Numeric_Value,msg->val);
  196.                                   break;
  197.     }
  198.    return(DoSuperMethodA(cl,obj,(Msg)msg));
  199.   }
  200.  
  201.  
  202.  static ULONG DateNavigator_New(struct IClass *cl, Object *obj, struct opSet *msg)
  203.   {
  204.    struct TagItem *tags,*tag;
  205.    ULONG inputmode,objectid=0;
  206.    Object *monthnavigator,*monthobj,*yearobj,*pyearobj,*myearobj,
  207.       *dayobj = NULL;
  208.  
  209.    inputmode = MUIV_MonthNavigator_InputMode_None;
  210.    /* Read new message attributes */
  211.    tags = msg->ops_AttrList;
  212.    while (tag = NextTagItem(&tags))
  213.     {
  214.      switch (tag->ti_Tag)
  215.       {
  216.        case MUIA_MonthNavigator_InputMode    : inputmode = (ULONG)tag->ti_Data;
  217.                                               break;
  218.        case MUIA_DateNavigator_ObjectID     : objectid = (ULONG)tag->ti_Data;
  219.                                                   break;
  220.       }
  221.     }
  222.    /* Create DateNavigator object */
  223.    obj = (Object *)DoSuperNew(cl,obj,
  224.                               MUIA_Group_Horiz,         FALSE,
  225.                               MUIA_Group_SameWidth,        TRUE,
  226.                               MUIA_Background,            MUII_GroupBack,
  227.                               MUIA_Frame,            MUIV_Frame_Group,
  228.                              MUIA_FrameTitle,            "DateNavigator",
  229.                               MUIA_Group_Child,            HGroup,
  230.                                 MUIA_Background,        MUII_GroupBack,
  231.                                 MUIA_Group_SameHeight,        TRUE,
  232.                                 MUIA_Group_Child,        RectangleObject,
  233.                                   MUIA_HorizWeight,        (inputmode == MUIV_MonthNavigator_InputMode_RelVerify) ? 100 : 50,
  234.                                 End,
  235.                                 MUIA_Group_Child,        (inputmode == MUIV_MonthNavigator_InputMode_RelVerify) ? dayobj = TextObject,
  236.                                   MUIA_Text_PreParse,        "\33r",
  237.                                   MUIA_Frame,            MUIV_Frame_Text,
  238.                                   MUIA_Background,        MUII_TextBack,
  239.                                   MUIA_FixWidthTxt,        "MM",
  240.                                 End :
  241.                                 RectangleObject,
  242.                                   MUIA_HorizWeight,        50,
  243.                                 End,
  244.                                 MUIA_Group_Child,        monthobj = CycleObject,
  245.                                   MUIA_Cycle_Entries,        months,
  246.                                   MUIA_Font,            MUIV_Font_Button,
  247.                                   MUIA_CycleChain,        1,
  248.                                 End,
  249.                                 MUIA_Group_Child,        yearobj = NumericbuttonObject,
  250.                                   MUIA_Numeric_Format,        "%lu",
  251.                                   MUIA_Numeric_Min,        8,
  252.                                   MUIA_Numeric_Max,        8000,
  253.                                   MUIA_Font,            MUIV_Font_Button,
  254.                                   MUIA_CycleChain,        1,
  255.                                 End,
  256.                                 MUIA_Group_Child,        myearobj = ImageObject,
  257.                                   MUIA_Frame,               MUIV_Frame_Button,
  258.                                   MUIA_InputMode,           MUIV_InputMode_RelVerify,
  259.                                   MUIA_Image_Spec,          MUII_ArrowLeft,
  260.                                   MUIA_Image_FreeVert,      TRUE,
  261.                                   MUIA_Background,          MUII_ButtonBack,
  262.                                   MUIA_ShowSelState,        FALSE,
  263.                                   MUIA_CycleChain,        1,
  264.                                 End,
  265.                                 MUIA_Group_Child,        pyearobj = ImageObject,
  266.                                   MUIA_Frame,               MUIV_Frame_Button,
  267.                                   MUIA_InputMode,           MUIV_InputMode_RelVerify,
  268.                                   MUIA_Image_Spec,          MUII_ArrowRight,
  269.                                   MUIA_Image_FreeVert,      TRUE,
  270.                                   MUIA_Background,          MUII_ButtonBack,
  271.                                   MUIA_ShowSelState,        FALSE,
  272.                                   MUIA_CycleChain,        1,
  273.                                 End,
  274.                                 MUIA_Group_Child,        RectangleObject,
  275.                                 End,
  276.                               End,
  277.                               MUIA_Group_Child,            monthnavigator = MonthNavigatorObject,
  278.                                 MUIA_Background,        MUII_GroupBack,
  279.                                 MUIA_MonthNavigator_InputMode,    inputmode,
  280.                                 MUIA_MonthNavigator_Draggable,    TRUE,
  281.                                 MUIA_ObjectID,            objectid,
  282.                                 /*MUIA_MonthNavigator_MarkHook,    / *&MarkHook* /MUIV_MonthNavigator_MarkHook_HiToday,*/
  283.                                 /*MUIA_Dropable,            FALSE,*/
  284.                                 MUIA_MonthNavigator_Dropable,        FALSE,
  285.                                 MUIA_CycleChain,        1,
  286.                               End,
  287.                               MUIA_Group_Child,            RectangleObject,
  288.                               End,
  289.                               TAG_MORE,             msg->ops_AttrList
  290.                              );
  291.    if (obj != NULL)
  292.     {
  293.      struct DateNavigator_Data *data = (struct DateNavigator_Data *)INST_DATA(cl,obj);
  294.      ULONG month,year,day;
  295.      char daystr[5];
  296.      /*ULONG result;*/
  297.  
  298.      /* Save pointers to sub-objects for later usage */
  299.      data->monthnavigator = monthnavigator;
  300.      data->month = monthobj;
  301.      data->year = yearobj;
  302.      data->day = dayobj;
  303.  
  304.      /* Init month/year/day with MonthNavigator values */
  305.      get(monthnavigator,MUIA_Date_Month,&month);
  306.      set(monthobj,MUIA_Cycle_Active,month-1);
  307.      get(monthnavigator,MUIA_Date_Year,&year);
  308.      set(yearobj,MUIA_Numeric_Default,year);
  309.      set(yearobj,MUIA_Numeric_Value,year);
  310.      if (dayobj != NULL)
  311.       {
  312.        get(monthnavigator,MUIA_Date_Day,&day);
  313.        date_FormatDate("%Ddv",(unsigned short)day,0,0,date_Locale,daystr);
  314.        set(dayobj,MUIA_Text_Contents,daystr);
  315.        /*result =*/ DoMethod(monthnavigator,MUIM_Notify,MUIA_Date_Day,MUIV_EveryTime,obj,1,MUIM_DateNavigator_UpdateDay);
  316.       }
  317.      /* Set notifies for interaction */
  318.      /*result =*/ DoMethod(monthnavigator,MUIM_Notify,MUIA_Date_Year, MUIV_EveryTime,yearobj,3,MUIM_NoNotifySet,MUIA_Numeric_Value,MUIV_TriggerValue);
  319.      /*result =*/ DoMethod(monthnavigator,MUIM_Notify,MUIA_Date_Month,MUIV_EveryTime,obj,    2,MUIM_DateNavigator_MonthUpdate,MUIV_TriggerValue);
  320.  
  321.      /*result =*/ DoMethod(myearobj,MUIM_Notify,MUIA_Pressed,FALSE,yearobj,2,MUIM_Numeric_Decrease,1);
  322.      /*result =*/ DoMethod(pyearobj,MUIM_Notify,MUIA_Pressed,FALSE,yearobj,2,MUIM_Numeric_Increase,1);
  323.  
  324.      /*result =*/ DoMethod(monthobj,MUIM_Notify,MUIA_Cycle_Active, MUIV_EveryTime,obj,1,MUIM_DateNavigator_Update);
  325.      /*result =*/ DoMethod(yearobj, MUIM_Notify,MUIA_Numeric_Value,MUIV_EveryTime,obj,1,MUIM_DateNavigator_Update);
  326.     }
  327.    return((ULONG)obj);
  328.   }
  329.  
  330.  
  331.  static ULONG SAVEDS_ASM DateNavigator_Dispatcher(REG(A0) struct IClass *cl, REG(A2) Object *obj, REG(A1) Msg msg)
  332.   {
  333.    switch (msg->MethodID)
  334.     {
  335.      case OM_NEW                : return(DateNavigator_New(cl,obj,(struct opSet *)msg));
  336.      case MUIM_DateNavigator_Update        : return(DateNavigator_Update(cl,obj,msg));
  337.      case MUIM_DateNavigator_UpdateDay        : return(DateNavigator_UpdateDay(cl,obj,msg));
  338.      case MUIM_DateNavigator_MonthUpdate    : return(DateNavigator_MonthUpdate(cl,obj,(struct MUIP_DateNavigator_MonthUpdate *)msg));
  339.      case MUIM_NoNotifySet            : return(DateNavigator_NoNotifySet(cl,obj,(struct MUIP_NoNotifySet *)msg));
  340.      default                    : return(DoSuperMethodA(cl,obj,msg));
  341.     }
  342.   }
  343.  
  344.  /* --- Window ------------------------------------------------------------- */
  345.  
  346.  static ULONG Win_New(struct IClass *cl, Object *obj, struct opSet *msg)
  347.   {
  348.    Object *DateString,*Day,*Month,*Year,*JD,*MJD,*saveobj,*loadobj,*format,*DNPop=NULL,*DN;
  349.  
  350.    DateString = DateStringObject,
  351.                   MUIA_Frame,            MUIV_Frame_String,
  352.                   MUIA_FrameTitle,        "DateString.mcc",
  353.                   MUIA_Background,        MUII_TextBack,
  354.                   MUIA_CycleChain,        1,
  355.                   MUIA_Draggable,        TRUE,
  356.                   /*MUIA_Dropable,        FALSE,*/
  357.                   /*MUIA_DateString_DateFormat,    "%d.%m.%Y",*/
  358.                   MUIA_String_AdvanceOnCR,    TRUE,
  359.                   MUIA_ObjectID,        1,
  360.                 End;
  361.    DN = NewObject(DateNavigator_CC->mcc_Class,NULL,
  362.                     MUIA_MonthNavigator_InputMode,    MUIV_MonthNavigator_InputMode_Immediate,
  363.           TAG_DONE
  364.              );
  365.  
  366.    if (DN != NULL)
  367.     {
  368.      DNPop = PopobjectObject,
  369.                MUIA_Popstring_Button,        PopButton(MUII_PopUp),
  370.                MUIA_Popstring_String,        DateString,
  371.                MUIA_Popobject_Object,        DN,
  372.              End;
  373.      if (DNPop != NULL)
  374.       {
  375.        /*result =*/ DoMethod(DN,MUIM_Notify,MUIA_Date_Year,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_Date_Year,MUIV_TriggerValue);
  376.        /*result =*/ DoMethod(DN,MUIM_Notify,MUIA_Date_Month,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_Date_Month,MUIV_TriggerValue);
  377.        /*result =*/ DoMethod(DN,MUIM_Notify,MUIA_Date_Day,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_Date_Day,MUIV_TriggerValue);
  378.        /*result =*/ DoMethod(DateString,MUIM_Notify,MUIA_Date_Year,MUIV_EveryTime,DN,3,MUIM_NoNotifySet,MUIA_Date_Year,MUIV_TriggerValue);
  379.        /*result =*/ DoMethod(DateString,MUIM_Notify,MUIA_Date_Month,MUIV_EveryTime,DN,3,MUIM_NoNotifySet,MUIA_Date_Month,MUIV_TriggerValue);
  380.        /*result =*/ DoMethod(DateString,MUIM_Notify,MUIA_Date_Day,MUIV_EveryTime,DN,3,MUIM_NoNotifySet,MUIA_Date_Day,MUIV_TriggerValue);
  381.       }
  382.      else
  383.       {
  384.        DateString = NULL;
  385.       }
  386.     }
  387.    obj = (Object *)DoSuperNew(cl,obj,
  388.                               MUIA_Window_ID,            MAKE_ID('D','E','M','O'),
  389.                               MUIA_Window_Title,        "DateString-Demo",
  390.                               MUIA_Window_ScreenTitle,        "DateString-Demo V12.3",
  391.                               MUIA_Window_RootObject,        VGroup,
  392.                                 MUIA_Group_SameWidth,        TRUE,
  393.                                 MUIA_Group_Child,        DNPop == NULL ? DateString : DNPop,
  394.                                 MUIA_Group_Child,        HGroup,
  395.                                   MUIA_Group_SameHeight,    TRUE,
  396.                                   MUIA_Frame,            MUIV_Frame_Group,
  397.                                   MUIA_Group_Child,        RectangleObject,
  398.                                   End,
  399.                                   MUIA_Group_Child,        Day = NumericbuttonObject,
  400.                                     MUIA_Numeric_Format,    "%lu",
  401.                                     MUIA_Numeric_Min,        1,
  402.                                     MUIA_Numeric_Max,        31,
  403.                                     MUIA_Numeric_Default,    1,
  404.                                     /*MUIA_Numeric_Value,    6,*/
  405.                                     MUIA_CycleChain,        1,
  406.                                     MUIA_Font,            MUIV_Font_Button,
  407.                                   End,
  408.                                   MUIA_Group_Child,        Month = NumericbuttonObject,
  409.                                     MUIA_Numeric_Format,    "%lu",
  410.                                     MUIA_Numeric_Min,        1,
  411.                                     MUIA_Numeric_Max,        12,
  412.                                     MUIA_Numeric_Default,    1,
  413.                                     /*MUIA_Numeric_Value,    6,*/
  414.                                     MUIA_CycleChain,        1,
  415.                                     MUIA_Font,            MUIV_Font_Button,
  416.                                   End,
  417.                                   MUIA_Group_Child,        Year = NumericbuttonObject,
  418.                                     MUIA_Numeric_Format,    "%lu",
  419.                                     MUIA_Numeric_Min,        8,
  420.                                     MUIA_Numeric_Max,        8000,
  421.                                     MUIA_Numeric_Default,    1997,
  422.                                     /*MUIA_Numeric_Value,    1997,*/
  423.                                     MUIA_CycleChain,        1,
  424.                                     MUIA_Font,            MUIV_Font_Button,
  425.                                   End,
  426.                                   MUIA_Group_Child,        RectangleObject,
  427.                                   End,
  428.                                 End,
  429.                                 MUIA_Group_Child,        HGroup,
  430.                                   MUIA_Frame,            MUIV_Frame_Group,
  431.                                   MUIA_Background,        MUII_GroupBack,
  432.                                   MUIA_Group_SameHeight,    TRUE,
  433.                                   MUIA_Group_Child,        RectangleObject,
  434.                                   End,
  435.                                   MUIA_Group_Child,        JD = NumericbuttonObject,
  436.                                     MUIA_Numeric_Format,    "%lu",
  437.                                     MUIA_Numeric_Min,        1723979,
  438.                                     MUIA_Numeric_Max,        2914672,
  439.                                     MUIA_Numeric_Default,    2450536,
  440.                                     /*MUIA_Numeric_Value,    2450536,*/
  441.                                     MUIA_CycleChain,        1,
  442.                                     MUIA_Font,            MUIV_Font_Button,
  443.                                   End,
  444.                                   MUIA_Group_Child,        MJD = NumericbuttonObject,
  445.                                     MUIA_Numeric_Format,    "%lu",
  446.                                     MUIA_Numeric_Min,        0,
  447.                                     MUIA_Numeric_Max,        514671,
  448.                                     MUIA_Numeric_Default,    50535,
  449.                                     /*MUIA_Numeric_Value,    50535,*/
  450.                                     MUIA_CycleChain,        1,
  451.                                     MUIA_Font,            MUIV_Font_Button,
  452.                                   End,
  453.                                   MUIA_Group_Child,        RectangleObject,
  454.                                   End,
  455.                                 End,
  456.                                 MUIA_Group_Child,        HGroup,
  457.                                   MUIA_Frame,            MUIV_Frame_Group,
  458.                                   MUIA_Background,        MUII_GroupBack,
  459.                                   MUIA_Group_SameHeight,    TRUE,
  460.                                   MUIA_Group_Child,        Label2("Format:"),
  461.                                   MUIA_Group_Child,        format = StringObject,
  462.                                     MUIA_Frame,            MUIV_Frame_String,
  463.                                     MUIA_Background,        MUII_TextBack,
  464.                                     MUIA_String_Accept,        "%.-/, edBbhmyYjwaAUWxDJfvs24nM",
  465.                                     MUIA_String_Format,        MUIV_String_Format_Left,
  466.                                     MUIA_String_MaxLen,        25,
  467.                                     MUIA_CycleChain,        1,
  468.                                   End,
  469.                                 End,
  470.                                 MUIA_Group_Child,        HGroup,
  471.                                   MUIA_Frame,            MUIV_Frame_Group,
  472.                                   MUIA_Background,        MUII_GroupBack,
  473.                                   MUIA_Group_SameHeight,    TRUE,
  474.                                   MUIA_Group_Child,        Label2("Drop here:"),
  475.                                   MUIA_Group_Child,        NewObject(Str_CC->mcc_Class,NULL,
  476.                     MUIA_Dropable,        TRUE,
  477.                     MUIA_Draggable,        TRUE,
  478.                   End,
  479.                                 End,
  480.                                 MUIA_Group_Child,        HGroup,
  481.                                   MUIA_Frame,            MUIV_Frame_Group,
  482.                                   MUIA_Background,        MUII_GroupBack,
  483.                                   MUIA_Group_SameHeight,    TRUE,
  484.                                   MUIA_Group_Child,        loadobj = TextObject,
  485.                                     MUIA_Frame,            MUIV_Frame_Button,
  486.                                     MUIA_Background,        MUII_ButtonBack,
  487.                                     MUIA_Font,            MUIV_Font_Button,
  488.                                     MUIA_Text_PreParse,        "\33c",
  489.                                     MUIA_InputMode,        MUIV_InputMode_RelVerify,
  490.                                     MUIA_Text_Contents,        "Load",
  491.                                     MUIA_Text_HiChar,        'L',
  492.                                     MUIA_ControlChar,        'l',
  493.                                     MUIA_CycleChain,        1,
  494.                                   End,
  495.                                   MUIA_Group_Child,        saveobj = TextObject,
  496.                                     MUIA_Frame,            MUIV_Frame_Button,
  497.                                     MUIA_Background,        MUII_ButtonBack,
  498.                                     MUIA_Font,            MUIV_Font_Button,
  499.                                     MUIA_Text_PreParse,        "\33c",
  500.                                     MUIA_InputMode,        MUIV_InputMode_RelVerify,
  501.                                     MUIA_Text_Contents,        "Save",
  502.                                     MUIA_Text_HiChar,        'S',
  503.                                     MUIA_ControlChar,        's',
  504.                                     MUIA_CycleChain,        1,
  505.                                   End,
  506.                                 End,
  507.                               End,
  508.                               TAG_MORE, msg->ops_AttrList
  509.                              );
  510.    if (obj != NULL)
  511.     {
  512.      /*struct Win_Data *data = (struct Win_Data *)INST_DATA(cl,obj);*/
  513.      /*ULONG result;*/
  514.      ULONG day,month,year,jd,mjd;
  515.      STRPTR dateformat;
  516.  
  517.      /*result =*/ DoMethod(DateString,MUIM_Date_SetCurrent);
  518.  
  519.      /*result =*/ get(DateString,MUIA_Date_Day,&day);
  520.      /*result =*/ get(DateString,MUIA_Date_Month,&month);
  521.      /*result =*/ get(DateString,MUIA_Date_Year,&year);
  522.      /*result =*/ get(DateString,MUIA_Date_JD,&jd);
  523.      /*result =*/ get(DateString,MUIA_Date_MJD,&mjd);
  524.      /*result =*/ set(Day,MUIA_Numeric_Value,day);
  525.      /*result =*/ set(Month,MUIA_Numeric_Value,month);
  526.      /*result =*/ set(Year,MUIA_Numeric_Value,year);
  527.      /*result =*/ set(JD,MUIA_Numeric_Value,jd);
  528.      /*result =*/ set(MJD,MUIA_Numeric_Value,mjd);
  529.  
  530.      /*result =*/ get(DateString,MUIA_DateString_DateFormat,&dateformat);
  531.      /*result =*/ set(format,MUIA_String_Contents,dateformat);
  532.  
  533.      /*result =*/ DoMethod(DateString,MUIM_Notify,MUIA_Date_Day,MUIV_EveryTime,Day,3,MUIM_NoNotifySet,MUIA_Numeric_Value,MUIV_TriggerValue);
  534.      /*result =*/ DoMethod(DateString,MUIM_Notify,MUIA_Date_Month,MUIV_EveryTime,Month,3,MUIM_NoNotifySet,MUIA_Numeric_Value,MUIV_TriggerValue);
  535.      /*result =*/ DoMethod(DateString,MUIM_Notify,MUIA_Date_Year,MUIV_EveryTime,Year,3,MUIM_NoNotifySet,MUIA_Numeric_Value,MUIV_TriggerValue);
  536.      /*result =*/ DoMethod(DateString,MUIM_Notify,MUIA_Date_JD,MUIV_EveryTime,JD,3,MUIM_NoNotifySet,MUIA_Numeric_Value,MUIV_TriggerValue);
  537.      /*result =*/ DoMethod(DateString,MUIM_Notify,MUIA_Date_MJD,MUIV_EveryTime,MJD,3,MUIM_NoNotifySet,MUIA_Numeric_Value,MUIV_TriggerValue);
  538.  
  539.      /*result =*/ DoMethod(Day,MUIM_Notify,MUIA_Numeric_Value,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_Date_Day,MUIV_TriggerValue);
  540.      /*result =*/ DoMethod(Month,MUIM_Notify,MUIA_Numeric_Value,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_Date_Month,MUIV_TriggerValue);
  541.      /*result =*/ DoMethod(Year,MUIM_Notify,MUIA_Numeric_Value,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_Date_Year,MUIV_TriggerValue);
  542.      /*result =*/ DoMethod(JD,MUIM_Notify,MUIA_Numeric_Value,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_Date_JD,MUIV_TriggerValue);
  543.      /*result =*/ DoMethod(MJD,MUIM_Notify,MUIA_Numeric_Value,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_Date_MJD,MUIV_TriggerValue);
  544.  
  545.      /*result =*/ DoMethod(format,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,DateString,3,MUIM_Set,MUIA_DateString_DateFormat,MUIV_TriggerValue);
  546.  
  547.      /*result =*/ DoMethod(loadobj,MUIM_Notify,MUIA_Pressed,FALSE,MUIV_Notify_Application,2,MUIM_Application_Load,MUIV_Application_Load_ENV);
  548.      /*result =*/ DoMethod(saveobj,MUIM_Notify,MUIA_Pressed,FALSE,MUIV_Notify_Application,2,MUIM_Application_Save,MUIV_Application_Save_ENV);
  549.     }
  550.    return((ULONG)obj);
  551.   }
  552.  
  553.  
  554.  static ULONG SAVEDS_ASM Win_Dispatcher(REG(A0) struct IClass *cl, REG(A2) Object *obj, REG(A1) Msg msg)
  555.   {
  556.    switch (msg->MethodID)
  557.     {
  558.      case OM_NEW            : return(Win_New(cl,obj,(struct opSet *)msg));
  559.      default                : return(DoSuperMethodA(cl,obj,msg));
  560.     }
  561.   }
  562.  
  563.  /* --- Application -------------------------------------------------------- */
  564.  
  565.  static ULONG App_New(struct IClass *cl, Object *obj, struct opSet *msg)
  566.   {
  567.    Object *win1;
  568.  
  569.    obj = (Object *)DoSuperNew(cl,obj,
  570.                               MUIA_Application_Title,           "DateString-Demo",
  571.                               MUIA_Application_Author,          "Kai Hofmann",
  572.                               MUIA_Application_Copyright,       "© 1996-1998 Kai Hofmann",
  573.                               MUIA_Application_Version,         "$VER: DateString-Demo 12.3 " __AMIGADATE__,
  574.                               MUIA_Application_Description,     "DateString demonstration program",
  575.                               MUIA_Application_Base,            "DSDEMO",
  576.                               MUIA_Application_SingleTask,      TRUE,
  577.                               MUIA_Application_Active,          TRUE,
  578.                               MUIA_Application_Window,        win1 = NewObject(Win_CC->mcc_Class,NULL,TAG_DONE),
  579.                               TAG_MORE, msg->ops_AttrList
  580.                              );
  581.    if (obj != NULL)
  582.     {
  583.      /*struct App_Data *data = (struct App_Data *)INST_DATA(cl,obj);*/
  584.      /*ULONG result;*/
  585.  
  586.      /*result =*/ DoMethod(win1,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  587.      set(win1,MUIA_Window_Open,TRUE);
  588.     }
  589.    return((ULONG)obj);
  590.   }
  591.  
  592.  
  593.  static ULONG SAVEDS_ASM App_Dispatcher(REG(A0) struct IClass *cl, REG(A2) Object *obj, REG(A1) Msg msg)
  594.   {
  595.    switch (msg->MethodID)
  596.     {
  597.      case OM_NEW            : return(App_New(cl,obj,(struct opSet *)msg));
  598.      default                : return(DoSuperMethodA(cl,obj,msg));
  599.     }
  600.   }
  601.  
  602.  /* ------------------------------------------------------------------------ */
  603.  
  604.  static void OpenReq(char *const str)
  605.   {
  606.    struct EasyStruct req =
  607.     {
  608.      sizeof(struct EasyStruct),
  609.      0,
  610.      "DateString-Demo",
  611.      NULL,
  612.      "OK",
  613.     };
  614.  
  615.    req.es_TextFormat = str;
  616.    EasyRequest(NULL,&req,NULL,(ULONG)MUIMASTER_VMIN);
  617.   }
  618.  
  619.  /* ------------------------------------------------------------------------ */
  620.  
  621.  static int muiclasses_Init(void)
  622.   {
  623.    int retstat = RETURN_OK;
  624.  
  625.    App_CC = MUI_CreateCustomClass(NULL,MUIC_Application,NULL,0,App_Dispatcher);
  626.    if (App_CC == NULL)
  627.     {
  628.      OpenReq("Can not create 'App' privat custom class!");
  629.      retstat = RETURN_ERROR;
  630.     }
  631.    else
  632.     {
  633.      Win_CC = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,0,Win_Dispatcher);
  634.      if (Win_CC == NULL)
  635.       {
  636.        OpenReq("Can not create 'Win' privat custom class!");
  637.        retstat = RETURN_ERROR;
  638.       }
  639.      else
  640.       {
  641.        Str_CC = MUI_CreateCustomClass(NULL,MUIC_String,NULL,0,Str_Dispatcher);
  642.        if (Str_CC == NULL)
  643.         {
  644.          OpenReq("Can not create 'Str' privat custom class!");
  645.          retstat = RETURN_ERROR;
  646.         }
  647.        else
  648.         {
  649.          DateNavigator_CC = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct DateNavigator_Data),DateNavigator_Dispatcher);
  650.          if (DateNavigator_CC == NULL)
  651.           {
  652.            OpenReq("Can not create 'DateNavigator' privat custom class!");
  653.            retstat = RETURN_ERROR;
  654.           }
  655.         }
  656.       }
  657.     }
  658.  
  659.    return(retstat);
  660.   }
  661.  
  662.  
  663.  static int muiclasses_Cleanup(void)
  664.   {
  665.    int retstat = RETURN_OK;
  666.  
  667.    if (DateNavigator_CC != NULL)
  668.     {
  669.      if (!MUI_DeleteCustomClass(DateNavigator_CC))
  670.       {
  671.        OpenReq("Can not delete 'DateNavigator' privat custom class!");
  672.        retstat = RETURN_ERROR;
  673.       }
  674.     }
  675.    if (Str_CC != NULL)
  676.     {
  677.      if (!MUI_DeleteCustomClass(Str_CC))
  678.       {
  679.        OpenReq("Can not delete 'Str' privat custom class!");
  680.        retstat = RETURN_ERROR;
  681.       }
  682.     }
  683.    if (Win_CC != NULL)
  684.     {
  685.      if (!MUI_DeleteCustomClass(Win_CC))
  686.       {
  687.        OpenReq("Can not delete 'Win' privat custom class!");
  688.        retstat = RETURN_ERROR;
  689.       }
  690.     }
  691.    if (App_CC != NULL)
  692.     {
  693.      if (!MUI_DeleteCustomClass(App_CC))
  694.       {
  695.        OpenReq("Can not delete 'App' privat custom class!");
  696.        retstat = RETURN_ERROR;
  697.       }
  698.     }
  699.  
  700.    return(retstat);
  701.   }
  702.  
  703.  /* ------------------------------------------------------------------------ */
  704.  
  705.  static int gui_Init(void)
  706.   {
  707.    int retstat;
  708.  
  709.    MUIMasterBase = OpenLibrary((UBYTE *)MUIMASTER_NAME,(unsigned long)MUIMASTER_VMIN);
  710.    if (MUIMasterBase != NULL)
  711.     {
  712.      retstat = muiclasses_Init();
  713.      if (retstat == RETURN_OK)
  714.       {
  715.        Object *ds;
  716.  
  717.        ds = MUI_NewObject(MUIC_DateString,
  718.                           TAG_DONE
  719.                          );
  720.        if (ds != NULL)
  721.         {
  722.          MUI_DisposeObject(ds);
  723.          App = NewObject(App_CC->mcc_Class,NULL,TAG_DONE);
  724.          if (App == NULL)
  725.           {
  726.            /*retstat =*/ muiclasses_Cleanup();
  727.            CloseLibrary(MUIMasterBase);
  728.            OpenReq("Can not create application object!");
  729.            retstat = RETURN_FAIL;
  730.           }
  731.         }
  732.        else
  733.         {
  734.          /*retstat =*/ muiclasses_Cleanup();
  735.          CloseLibrary(MUIMasterBase);
  736.          OpenReq("Missing DateString.mcc!");
  737.          retstat = RETURN_FAIL;
  738.         }
  739.       }
  740.      else
  741.       {
  742.        /*retstat =*/ muiclasses_Cleanup();
  743.        CloseLibrary(MUIMasterBase);
  744.       }
  745.     }
  746.    else
  747.     {
  748.      OpenReq("Can not open muimaster.library V%lu!");
  749.      retstat = RETURN_FAIL;
  750.     }
  751.    return(retstat);
  752.   }
  753.  
  754.  
  755.  static int gui_Cleanup(void)
  756.   {
  757.    int retstat = RETURN_OK;
  758.  
  759.    if (MUIMasterBase != NULL)
  760.     {
  761.      if (App != NULL)
  762.       {
  763.        MUI_DisposeObject(App);
  764.       }
  765.      retstat = muiclasses_Cleanup();
  766.      if (retstat == RETURN_OK)
  767.       {
  768.        CloseLibrary(MUIMasterBase);
  769.       }
  770.      else
  771.       {
  772.        OpenReq("Can not close muimaster.library!");
  773.        retstat = RETURN_FAIL;
  774.       }
  775.     }
  776.    return(retstat);
  777.   }
  778.  
  779.  
  780.  static void gui_MainLoop(void)
  781.   {
  782.    if (App != NULL)
  783.     {
  784.      ULONG signals=0;
  785.  
  786.      while (DoMethod(App,(unsigned long)MUIM_Application_NewInput,&signals) != MUIV_Application_ReturnID_Quit)
  787.       {
  788.        if (signals)
  789.         {
  790.          signals = Wait(signals | SIGBREAKF_CTRL_C);
  791.          if (signals & SIGBREAKF_CTRL_C)
  792.           {
  793.            /*ULONG result;*/
  794.  
  795.            /*result =*/ DoMethod(App,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  796.           }
  797.         }
  798.       }
  799.     }
  800.   }
  801.  
  802.  /* ------------------------------------------------------------------------ */
  803.  
  804.  void main(void)
  805.   {
  806.    BOOL error = FALSE;
  807.  
  808.    DateBase = OpenLibrary(DATE_NAME,33);
  809.    if (DateBase != NULL)
  810.     {
  811.      if (((DateBase->lib_Version > 33)) || ((DateBase->lib_Version == 33) && (DateBase->lib_Revision >= 290)))
  812.       {
  813.        short i;
  814.        char mn[15];
  815.        APTR mempool;
  816.  
  817.        mempool = LibCreatePool(MEMF_PUBLIC,180,15);
  818.        if (mempool != NULL)
  819.         {
  820.          for (i=0;i<12;i++)
  821.           {
  822.            date_MonthText(i+1,mn,date_Locale);
  823.            months[i] = (char *)LibAllocPooled(mempool,(ULONG)strlen(mn)+1);
  824.            if (months[i] != NULL)
  825.             {
  826.              strcpy(months[i],mn);
  827.             }
  828.            else
  829.             {
  830.              OpenReq("Out of memory error!");
  831.              error = TRUE;
  832.              break;
  833.             }
  834.           }
  835.          if (!error)
  836.           {
  837.            months[12] = NULL;
  838.            if (gui_Init() == RETURN_OK)
  839.             {
  840.              gui_MainLoop();
  841.              /*result =*/ gui_Cleanup();
  842.             }
  843.           }
  844.      LibDeletePool(mempool);
  845.         }
  846.       }
  847.      else
  848.       {
  849.        OpenReq("Can not open date.library V33.290");
  850.       }
  851.      CloseLibrary(DateBase);
  852.     }
  853.    else
  854.     {
  855.      OpenReq("Can not open date.library V33");
  856.     }
  857.   }
  858.