1 #include <aros/oldprograms.h>
3 #include <intuition/intuition.h>
8 #include <exec/nodes.h>
9 #include <exec/lists.h>
10 #include <exec/memory.h>
14 extern int Month2Num(char *);
15 extern int DisplayC(char **);
16 extern void DisplayE(char **);
17 extern void DisplayH(char **);
18 extern BOOL
CheckMemoDate(char *);
20 extern struct MinList
*MemListPtr
;
21 extern struct MinNode
*DisplayFirst
;
22 extern struct Remember
*RK
;
25 /*--------------------------------------------------------------------------
26 * Prototypes for functions in this module
32 BOOL
MemoReq(struct Memo_Item
*);
33 BOOL
MemIns(struct MI_Mem
*);
34 BOOL
MemoDel(struct MI_Mem
*);
36 BOOL DataAmended
= FALSE
;
37 extern struct IntuitionBase
*IntuitionBase
;
38 extern void Display_Block(struct MinNode
*);
39 BOOL
MemoReq(struct Memo_Item
*);
41 static struct IntuiText memo_string_text
=
43 1, 0, JAM1
, 0, -10, NULL
, "Memo:", NULL
45 static struct IntuiText date_string_text
=
47 1, 0, JAM1
, -50, 0, NULL
, "Date:", NULL
49 static struct IntuiText notice_string_text
=
51 1, 0, JAM1
, -80, 0, NULL
, "Notice:", NULL
53 static struct IntuiText type_string_text
=
55 1, 0, JAM1
, -50, 0, NULL
, "Type:", NULL
57 static struct IntuiText ok_text
=
59 1, 0, JAM1
, 4, 2, NULL
, " OK ", NULL
61 static struct IntuiText help_text
=
63 1, 0, JAM1
, 4, 2, NULL
, " HELP ", NULL
65 static struct IntuiText cancel_text
=
67 1, 0, JAM1
, 4, 2, NULL
, "CANCEL", NULL
69 static struct IntuiText requester_text
=
71 1, 0, JAM1
, 14, 3, NULL
, "Please enter your memo:", NULL
74 static UBYTE memo_buffer
[61];
75 static UBYTE undo_buffer
[61];
76 static UBYTE date_buffer
[10];
77 static UBYTE notice_buffer
[3];
78 static UBYTE type_buffer
[2];
80 static struct StringInfo memo_string_info
=
82 memo_buffer
, undo_buffer
, 0, 61,
84 static struct StringInfo date_string_info
=
86 date_buffer
, undo_buffer
, 0, 10,
88 static struct StringInfo notice_string_info
=
90 notice_buffer
, undo_buffer
, 0, 3,
92 static struct StringInfo type_string_info
=
94 type_buffer
, undo_buffer
, 0, 2,
97 /*----------------------------------------------------------------------
98 * data for string gadgets etc
101 static SHORT type_bpts
[]=
105 DEA_TYPE_W
-2, DEA_SGAD_H
,
110 static SHORT memo_bpts
[]=
114 DEA_MEMO_W
-2, DEA_SGAD_H
,
119 static SHORT date_bpts
[]=
123 DEA_DATE_W
-2, DEA_SGAD_H
,
128 static SHORT noti_bpts
[]=
132 DEA_NOTI_W
-3, DEA_SGAD_H
,
137 static struct Border type_brd
=
139 0, 0, 0, 0, JAM1
, 5, type_bpts
, NULL
142 static struct Border memo_brd
=
144 0, 0, 0, 0, JAM1
, 5, memo_bpts
, NULL
147 static struct Border date_brd
=
149 0, 0, 0, 0, JAM1
, 5, date_bpts
, NULL
152 static struct Border noti_brd
=
154 0, 0, 0, 0, JAM1
, 5, noti_bpts
, NULL
157 static struct Gadget memo_gadget
=
159 NULL
, 20, 32, DEA_MEMO_W
, DEA_SGAD_H
, GADGHCOMP
, RELVERIFY
,
160 STRGADGET
|REQGADGET
,(APTR
)&memo_brd
,NULL
,&memo_string_text
, 0,
161 (APTR
) &memo_string_info
,0,NULL
164 static struct Gadget date_gadget
=
166 &memo_gadget
,100, 14, DEA_DATE_W
, DEA_SGAD_H
, GADGHCOMP
, RELVERIFY
,
167 STRGADGET
|REQGADGET
, (APTR
)&date_brd
, NULL
, &date_string_text
, 0,
168 (APTR
) &date_string_info
, 0, NULL
170 static struct Gadget notice_gadget
=
172 &date_gadget
,300, 14, DEA_NOTI_W
, DEA_SGAD_H
, GADGHCOMP
, RELVERIFY
,
173 STRGADGET
|REQGADGET
, (APTR
)¬i_brd
, NULL
, ¬ice_string_text
, 0,
174 (APTR
) ¬ice_string_info
, 0, NULL
176 static struct Gadget type_gadget
=
178 ¬ice_gadget
,400, 14, DEA_TYPE_W
, DEA_SGAD_H
, GADGHCOMP
, RELVERIFY
,
179 STRGADGET
|REQGADGET
, (APTR
)&type_brd
, NULL
, &type_string_text
, 0,
180 (APTR
) &type_string_info
, 0, NULL
183 /*---------------------------------------------------------------------
184 * data for BOOLEAN gadgets
186 static SHORT bb_pts_tr
[]= /*Top left points*/
193 static SHORT bb_pts_bl
[]= /*Bottom right points*/
200 static struct Border bb0_tr
=
202 0, 0, 0, 0, JAM1
, 3, bb_pts_tr
, NULL
205 static struct Border bb0_bl
=
207 0, 0, 0, 0, JAM1
, 3, bb_pts_bl
, &bb0_tr
210 static struct Border bb1_tr
=
212 0, 0, 0, 0, JAM1
, 3, bb_pts_tr
, NULL
215 static struct Border bb1_bl
=
217 0, 0, 0, 0, JAM1
, 3, bb_pts_bl
, &bb1_tr
220 static struct Gadget ok_gadget
=
222 &type_gadget
, /* NextGadget */
225 DEA_BGAD_W
, /* Width */
227 GADGHIMAGE
, /* Flags */
228 RELVERIFY
| /* Activation */
230 BOOLGADGET
| /* GadgetType */
232 (APTR
) &bb0_bl
, /* GadgetRender */
233 (APTR
) &bb1_bl
, /* SelectRender */
234 &ok_text
, /* GadgetText */
237 static struct Gadget help_gadget
=
239 &ok_gadget
,314, 47, DEA_BGAD_W
, DEA_BGAD_H
, GADGHIMAGE
, RELVERIFY
,
240 BOOLGADGET
|REQGADGET
, (APTR
)&bb0_bl
, (APTR
)&bb1_bl
, &help_text
,
243 static struct Gadget cancel_gadget
=
245 &help_gadget
,514, 47, DEA_BGAD_W
, DEA_BGAD_H
, GADGHIMAGE
, RELVERIFY
|ENDGADGET
,
246 BOOLGADGET
|REQGADGET
, (APTR
)&bb0_bl
, (APTR
)&bb1_bl
, &cancel_text
,
249 static SHORT requester_border_points
[]=
258 static struct Border requester_border
=
260 0, 0, /* LeftEdge, TopEdge. */
265 requester_border_points
, /* XY */
266 NULL
, /* NextBorder */
270 static struct Requester my_requester
=
272 NULL
, /* OlderRequester */
273 0, 10, /* LeftEdge, TopEdge */
274 640, 65, /* Width, Height */
275 0, 0, /* RelLeft, RelTop */
276 &cancel_gadget
, /* ReqGadget */
277 &requester_border
, /* ReqBorder */
278 &requester_text
, /* ReqText */
281 static struct Window
*my_window
;
283 static struct NewWindow my_new_window
=
291 GADGETUP
| /* IDCMPFlags */
293 SMART_REFRESH
| /* Flags */
297 NULL
, /* FirstGadget */
298 NULL
, /* CheckMark */
299 "Amigaholics!!!", /* Title */
306 WBENCHSCREEN
/* Type */
309 static char *MAdd_Help
[]={
311 " Date format is \"dd-mmm-yy\" ",
312 " eg \"21-JAN-91\" ",
313 " Notice is number, 1 to 99. The ",
314 " number of days notice you want",
315 " Type is A (or a) for Annual ",
316 " anything else is up to you ",
320 static char *err_txt_reqfail
[]={
322 " Failed to open ADD requester ",
326 static char *err_txt_fopenfail
[]={
328 " Failed to open memo file ",
332 static char *err_txt_dateinv2
[]={
334 " Couldn\'t write since date was invalid ",
337 /*--------------------------------------------------------------------------
338 * Function Edit() calls MemoReq() for each selected memo in the list. Prior
339 * to the call, Edit() sets up the current field values in a Memo_Item
340 * structure. Returns TRUE if no errors found, otherwise FALSE. (Actually,
341 * it currently returns TRUE under all circumstances.
350 if (LISTEMPTY
) return TRUE
;
351 n
=MemListPtr
->mlh_Head
;
354 if ( ((struct MI_Mem
*)n
)->mim_Select
== 1)
356 strcpy(m
.mi_Date
, ((struct MI_Mem
*)n
)->mim_MI
.mi_Date
);
357 strcpy(m
.mi_Notice
, ((struct MI_Mem
*)n
)->mim_MI
.mi_Notice
);
358 strcpy(m
.mi_Type
, ((struct MI_Mem
*)n
)->mim_MI
.mi_Type
);
359 strcpy(m
.mi_Text
, ((struct MI_Mem
*)n
)->mim_MI
.mi_Text
);
360 result
= MemoReq(&m
);
363 strcpy( ((struct MI_Mem
*)n
)->mim_MI
.mi_Date
, m
.mi_Date
);
364 strcpy( ((struct MI_Mem
*)n
)->mim_MI
.mi_Notice
, m
.mi_Notice
);
365 strcpy( ((struct MI_Mem
*)n
)->mim_MI
.mi_Type
, m
.mi_Type
);
366 strcpy( ((struct MI_Mem
*)n
)->mim_MI
.mi_Text
, m
.mi_Text
);
367 Remove((struct Node
*)n
);
368 MemIns((struct MI_Mem
*)n
);
372 ((struct MI_Mem
*)n
)->mim_Select
=0;
375 Display_Block(DisplayFirst
);
379 /*--------------------------------------------------------------------------
380 * Function Add() calls MemoReq() to get data for new memo.
381 * Returns TRUE if no errors found, otherwise FALSE. (Actually,
382 * it currently returns TRUE under all circumstances.
397 mim
=(struct MI_Mem
*)AllocRemember(&RK
,sizeof(struct MI_Mem
),MEMF_PUBLIC
);
398 if (!mim
) return FALSE
;
399 strcpy( mim
->mim_MI
.mi_Date
, m
.mi_Date
);
400 strcpy( mim
->mim_MI
.mi_Notice
, m
.mi_Notice
);
401 strcpy( mim
->mim_MI
.mi_Type
, m
.mi_Type
);
402 strcpy( mim
->mim_MI
.mi_Text
, m
.mi_Text
);
405 if (!result
) return FALSE
;
406 Display_Block(DisplayFirst
);
412 /*--------------------------------------------------------------------------
413 * Function Del() reads through Memo list and, with the confirmation of the
414 * user, deletes selected memos. The memos are actually just removed from
415 * the list, the memory is not released until the program terminates. (Later
416 * deleted memos could be organised as a separate list and a process made
417 * available for the user to change his/her mind and reinsert any memos?)
418 * Returns TRUE if no errors found, otherwise FALSE. (Actually,
419 * it currently returns TRUE under all circumstances.
427 if (LISTEMPTY
) return TRUE
;
428 n
=MemListPtr
->mlh_Head
;
431 if ( ((struct MI_Mem
*)n
)->mim_Select
== 1)
433 result
= MemoDel((struct MI_Mem
*)n
);
436 Remove((struct Node
*)n
);
438 if (( n
= DisplayFirst
))
443 DisplayFirst
= MemListPtr
->mlh_Head
;
445 Display_Block(DisplayFirst
);
453 /*--------------------------------------------------------------------------
454 * Function MemIns() allocates a new MI_Mem structure in memory, copies
455 * data into it from a Memo_Item structure whose address was given as a
456 * parameter and then returns TRUE if no errors found, otherwise FALSE.
458 BOOL
MemIns(struct MI_Mem
*m
)
467 AddHead((struct List
*)MemListPtr
,(struct Node
*)m
);
471 mnum
= Month2Num((char *)&(m
->mim_MI
.mi_Date
[3]));
472 sprintf(d1
, "%02d", mnum
);
473 d1
[2]=m
->mim_MI
.mi_Date
[0];
474 d1
[3]=m
->mim_MI
.mi_Date
[1];
476 n
=MemListPtr
->mlh_Head
;
478 while ( (!found
) && (n
->mln_Succ
) )
480 mnum
= Month2Num((char *)&(((struct MI_Mem
*)n
)->mim_MI
.mi_Date
[3]));
481 sprintf(d2
, "%02d", mnum
);
482 d2
[2]=((struct MI_Mem
*)n
)->mim_MI
.mi_Date
[0];
483 d2
[3]=((struct MI_Mem
*)n
)->mim_MI
.mi_Date
[1];
492 Insert( (struct List
*)MemListPtr
,(struct Node
*)m
,(struct Node
*)n
->mln_Pred
);
496 if (!found
) AddTail( (struct List
*)MemListPtr
, (struct Node
*)m
);
502 /* -------------------------------------------------------------------
503 * Function handling Requester allowing addition of new memos and
504 * editing of existing ones
506 BOOL
MemoReq(struct Memo_Item
*mim
)
511 struct IntuiMessage
*my_message
;
513 int MemoState
,DateState
;
514 char *err_txt_dateinv1
[] = {
516 " Invalid date - try again ",
520 my_new_window
.DetailPen
= Colour
[0];
521 my_new_window
.BlockPen
= Colour
[1];
522 requester_border
.FrontPen
= Colour
[2];
523 requester_border
.BackPen
= Colour
[0];
524 type_brd
.FrontPen
= Colour
[2];
525 type_brd
.BackPen
= Colour
[0];
526 memo_brd
.FrontPen
= Colour
[2];
527 memo_brd
.BackPen
= Colour
[0];
528 date_brd
.FrontPen
= Colour
[2];
529 date_brd
.BackPen
= Colour
[0];
530 noti_brd
.FrontPen
= Colour
[2];
531 noti_brd
.BackPen
= Colour
[0];
532 bb0_bl
.FrontPen
= Colour
[2];
533 bb0_bl
.BackPen
= Colour
[1];
534 bb0_tr
.FrontPen
= Colour
[1];
535 bb0_tr
.BackPen
= Colour
[2];
536 bb1_bl
.FrontPen
= Colour
[1];
537 bb1_bl
.BackPen
= Colour
[2];
538 bb1_tr
.FrontPen
= Colour
[2];
539 bb1_tr
.BackPen
= Colour
[1];
540 my_requester
.BackFill
= Colour
[0];
541 strcpy(date_buffer
,mim
->mi_Date
);
542 strcpy(memo_buffer
,mim
->mi_Text
);
543 strcpy(notice_buffer
,mim
->mi_Notice
);
544 strcpy(type_buffer
,mim
->mi_Type
);
545 my_window
= (struct Window
*) OpenWindow( &my_new_window
);
546 if(my_window
== NULL
)
548 CloseLibrary( (struct Library
*)IntuitionBase
);
552 result
=Request( &my_requester
, my_window
);
555 DisplayE(err_txt_reqfail
);
561 ActivateGadget(&date_gadget
,
566 Wait( 1 << my_window
->UserPort
->mp_SigBit
);
567 while((my_message
=(struct IntuiMessage
*) GetMsg(my_window
->UserPort
)))
569 class = my_message
->Class
;
570 address
= my_message
->IAddress
;
571 ReplyMsg( (struct Message
*)my_message
);
575 if(address
== (APTR
) &ok_gadget
)
579 if(address
== (APTR
) &help_gadget
)
582 ActivateGadget(&date_gadget
,
586 if(address
== (APTR
) &cancel_gadget
)
590 if(address
== (APTR
) &date_gadget
)
592 if(CheckMemoDate(date_buffer
) == TRUE
)
595 ActivateGadget(¬ice_gadget
,
602 DisplayE(err_txt_dateinv1
);
603 ActivateGadget(&date_gadget
,
608 if(address
== (APTR
) &memo_gadget
)
610 ActivateGadget(&date_gadget
,
615 if(address
== (APTR
) ¬ice_gadget
)
617 ActivateGadget(&type_gadget
,
622 if(address
== (APTR
) &type_gadget
)
625 ActivateGadget(&memo_gadget
,
639 if(CheckMemoDate(date_buffer
) == TRUE
)
643 CloseWindow( my_window
);
648 strcpy(mim
->mi_Date
,date_buffer
);
649 strcpy(mim
->mi_Notice
,notice_buffer
);
650 strcpy(mim
->mi_Type
,type_buffer
);
651 strcpy(mim
->mi_Text
,memo_buffer
);
656 DisplayE(err_txt_dateinv2
);
667 /*======================================================================*/
668 BOOL
MemoDel(struct MI_Mem
*memo
)
672 " Do you want to delete this memo? ",
679 char dbuff
[18]; /* "Date : dd-mmm-yy" */
680 char tbuff
[10]; /* "Type : X" */
682 sprintf(tbuff
, "Type : %s", memo
->mim_MI
.mi_Type
);
683 sprintf(dbuff
, "Date : %s", memo
->mim_MI
.mi_Date
);
686 Query
[5]=memo
->mim_MI
.mi_Text
;
687 return DisplayC(Query
);