home *** CD-ROM | disk | FTP | other *** search
/ BUG 1 / BUGCD1996_0708.ISO / pc / util / clysbr / calend.pa_ / calend.pa
Text File  |  1995-02-28  |  11KB  |  399 lines

  1. Library Calend;
  2.  
  3. { Calend Add-In for the clySmic Icon Bar. (C) 1995 by clySmic Software.
  4.                                           All Rights reserved. }
  5.  
  6. {define Debug}
  7.  
  8. {$ifndef Debug}
  9. {$R-,I-,D-,L-,S-,V-,W-,G+}
  10. {$endif}
  11.  
  12. {$C MOVEABLE PRELOAD DISCARDABLE}
  13.  
  14. Uses
  15.   WinTypes,WinProcs,Strings,WinDOS,TPWTools;
  16.  
  17. {$R CALEND}
  18. {$I ADD-IN.INC}
  19. {$I ..\VER}
  20.  
  21. Const
  22.   ShowDOW : Boolean = True;
  23.   CLBVer : VerString = AddInMasterVer;
  24.  
  25. Var
  26.   Yr,Mon,Day,DOW : Word;
  27.   CalendProgram,IWDate,INIFile : Array [0..80] of Char;
  28.   GTxInBtn,USDateFormat : Boolean;
  29.  
  30. {$D Calend Add-In for Clysbar - clySmic Software}
  31.  
  32. {-----------------------------------------------}
  33.  
  34. { --- Utility Procedures --- }
  35.  
  36. Function CenterTx(DC : HDC; Tx : PChar; Rect : TRect) : Integer;
  37.  
  38. Var
  39.   Width,WinX,StrtX : Integer;
  40.  
  41. Begin
  42.   { Ask Windows for the total pixel length of the string & calc starting X }
  43.   Width := LoWord(GetTextExtent(DC,Tx,StrLen(Tx)));
  44.  
  45.   { Get total x width of window - don't add 1! }
  46.   WinX := (Rect.Right - Rect.Left);
  47.  
  48.   { Calculate centered starting posn }
  49.   StrtX := ((WinX - Width) Div 2) + Rect.Left;
  50.  
  51.   { Return }
  52.   CenterTx := StrtX;
  53. End {CenterTx};
  54.  
  55. {-----------------------------------------------}
  56.  
  57. Procedure FormIWDate;
  58.  
  59. Const
  60.   MonthName : Array [1..12] of PChar =
  61.     ('January','February','March','April','May','June',
  62.      'July','August','September','October','November','December');
  63.  
  64.   Days : array [0..6] of PChar =
  65.      ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  66.  
  67. Var
  68.   StrDay,StrYr : Array [0..4] of Char;
  69.  
  70. Begin
  71.   GetDate(Yr,Mon,Day,DOW);
  72.   Str(Day,StrDay);
  73.   Str(Yr,StrYr);
  74.  
  75.   If USDateFormat
  76.     Then Begin
  77.            { US date fmt }
  78.            StrCopy(IWDate,Days[DOW]);
  79.            StrCat(IWDate,', ');
  80.            StrCat(IWDate,MonthName[Mon]);
  81.            StrCat(IWDate,' ');
  82.            StrCat(IWDate,StrDay);
  83.            StrCat(IWDate,', ');
  84.            StrCat(IWDate,StrYr);
  85.          End
  86.     Else Begin
  87.            { European date fmt }
  88.            StrCopy(IWDate,Days[DOW]);
  89.            StrCat(IWDate,', ');
  90.            StrCat(IWDate,StrDay);
  91.            StrCat(IWDate,' ');
  92.            StrCat(IWDate,MonthName[Mon]);
  93.            StrCat(IWDate,' ');
  94.            StrCat(IWDate,StrYr);
  95.          End;
  96. End {FormIWDate};
  97.  
  98. {-----------------------------------------------}
  99.  
  100. { --- Perform Add-In's initialization --- }
  101.  
  102. Function AddInInit(CurVer : PChar; TxInBtn : Boolean) : InitResult; Export;
  103.  
  104. Begin
  105.   { Version check }
  106.   If StrLComp(CurVer,CLBVer,3) <> 0
  107.     Then AddInInit := InitNotOk
  108.     Else AddInInit := InitOk;
  109.  
  110.   { Point at our INI file, which is in our home dir }
  111.   HomeDir(hInstance,INIFile,Sizeof(INIFile));
  112.   StrCat(INIFile,'CALEND.INI');
  113.  
  114.   { Flush INI file so we can edit it }
  115.   WritePrivateProfileString(Nil,Nil,Nil,INIFile);
  116.  
  117.   { Get date format }
  118.   USDateFormat := Boolean(GetPrivateProfileInt('Settings',
  119.                                                'USDateFormat',
  120.                                                0,
  121.                                                INIFile));
  122.  
  123.   { Get program to run if shift-clicked. Default = Schedule+ }
  124.   GetPrivateProfileString('Settings',
  125.                           'CalendProgram',
  126.                           'SCHDPLUS.EXE',
  127.                           CalendProgram,
  128.                           SizeOf(CalendProgram),
  129.                           INIFile);
  130.  
  131.   { Save text-in-button flag }
  132.   GTxInBtn := TxInBtn;
  133. End {AddInInit};
  134.  
  135. {-----------------------------------------------}
  136.  
  137. { --- Paint on the button (Clysbar does the background) --- }
  138.  
  139. Procedure AddInPaint(Wnd : HWnd; DC : HDC; Pressed : Boolean); Export;
  140.  
  141. Const
  142.   MonthName : Array [1..12] of PChar =
  143.     ('JAN','FEB','MAR','APR','MAY','JUN',
  144.      'JUL','AUG','SEP','OCT','NOV','DEC');
  145.  
  146.   Days : array [0..6] of PChar =
  147.      ('SUN','MON','TUE','WED','THU','FRI','SAT');
  148.  
  149. Var
  150.   ShadRect,Rect : TRect;
  151.   NumFont,OldFont,SmlFont : HFont;
  152.   Tx : Array[0..128] of Char;
  153.   StrYr,StrDay : Array [0..4] of Char;
  154.   StrtX,StrtY : Integer;
  155.   TheIcon : HIcon;
  156.  
  157. Begin
  158.   { If add-in is never uncovered, Wnd will be NULL }
  159.   If Wnd = 0
  160.     Then Exit;
  161.  
  162.   GetClientRect(Wnd,Rect);
  163.   If GTxInBtn
  164.     Then Rect.Right := Rect.Left + GetSystemMetrics(sm_cxIcon) + 12;
  165.  
  166.   { Calc location of icon }
  167.   StrtX := ((Rect.Right - Rect.Left) - GetSystemMetrics(sm_cxIcon)) Div 2;
  168.   StrtY := ((Rect.Bottom - Rect.Top) - GetSystemMetrics(sm_cyIcon)) Div 2;
  169.  
  170.   { Draw turning page if pressed }
  171.   If Pressed
  172.     Then Begin
  173.            TheIcon := LoadIcon(hInstance,'turning');
  174.            DrawIcon(DC,StrtX+1,StrtY+1,TheIcon);
  175.  
  176.            Exit;
  177.          End;
  178.  
  179.   { Draw "page" icon }
  180.   TheIcon := LoadIcon(hInstance,'calend');
  181.   DrawIcon(DC,StrtX,StrtY,TheIcon);
  182.  
  183.   { Get date info }
  184.   GetDate(Yr,Mon,Day,DOW);
  185.   Str(Day,StrDay);
  186.   Str(Yr,StrYr);
  187.  
  188.   { Create small font for the month/day/year }
  189.   SmlFont :=
  190.   CreateFont(9,             { Height }
  191.              0,0,0,         { Width, left 2 right, normal orientation }
  192.              400,           { Weight }
  193.              0,0,0,         { Italic, underlined, or strikeout }
  194.              0,             { ANSI char set }
  195.              0,             { Reserved precision field }
  196.              0,             { Default clipping }
  197.              Proof_Quality, { Quality }
  198.              ff_Roman Or Variable_Pitch,
  199.              'Small Fonts');
  200.  
  201.   { Create large font for the day number }
  202.   NumFont :=
  203.   CreateFont(17,            { Height }
  204.              0,0,0,         { Width, left 2 right, normal orientation }
  205.              700,           { Weight }
  206.              0,0,0,         { Italic, underlined, or strikeout }
  207.              0,             { ANSI char set }
  208.              0,             { Reserved precision field }
  209.              0,             { Default clipping }
  210.              Proof_Quality, { Quality }
  211.              ff_Roman Or Variable_Pitch,
  212.              'Times New Roman');
  213.  
  214.   { Setup for day number }
  215.   OldFont := SelectObject(DC,NumFont);
  216.   SetBkMode(DC,Transparent);
  217.  
  218.   { Draw lg day number's shadow }
  219.   SetTextColor(DC,RGB(128,128,128));
  220.   ShadRect := Rect;
  221.   OffsetRect(ShadRect,2,1);
  222.   DrawText(DC,StrDay,StrLen(StrDay),ShadRect,
  223.            dt_Center or dt_VCenter or dt_SingleLine);
  224.  
  225.   { Draw lg day number }
  226.   SetTextColor(DC,RGB(0,0,0));
  227.   OffsetRect(Rect,1,0);
  228.   DrawText(DC,StrDay,StrLen(StrDay),Rect,
  229.            dt_Center or dt_VCenter or dt_SingleLine);
  230.  
  231.   { Setup for other info }
  232.   SelectObject(DC,SmlFont);
  233.  
  234.   { Draw month name }
  235.   StrCopy(Tx,MonthName[Mon]);
  236.   SetTextColor(DC,RGB(255,0,0));
  237.   OffsetRect(Rect,-1,0);
  238.   TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 1,Tx,StrLen(Tx));
  239.  
  240.   { Either year or doy }
  241.   If ShowDOW
  242.     Then Begin
  243.            { Display day of week }
  244.            StrCopy(Tx,Days[DOW]);
  245.            SetTextColor(DC,RGB(0,0,128));
  246.            OffsetRect(Rect,-1,0);
  247.            TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 22,Tx,StrLen(Tx));
  248.          End
  249.     Else Begin
  250.            { Display year }
  251.            StrCopy(Tx,StrYr);
  252.            SetTextColor(DC,RGB(128,0,128));
  253.            TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 22,Tx,StrLen(Tx));
  254.          End;
  255.  
  256.   { Clean up }
  257.   SelectObject(DC,OldFont);
  258.   DeleteObject(SmlFont);
  259.   DeleteObject(NumFont);
  260. End {AddInPaint};
  261.  
  262. {-----------------------------------------------}
  263.  
  264. { --- Tell Clysbar what kind of timer we need --- }
  265.  
  266. Function AddInTimerNeeded : Integer; Export;
  267.  
  268. Begin
  269.   AddInTimerNeeded := ait_Slow;
  270. End {AddInTimerNeeded};
  271.  
  272. {-----------------------------------------------}
  273.  
  274. { --- Proc called when timer expires, perform timed duties --- }
  275.  
  276. Procedure AddInTimerTick(Wnd : HWnd; DC : HDC); Export;
  277.  
  278. Var
  279.   TimerDay : Word;
  280.  
  281. Begin
  282.   { Check for a date change }
  283.   GetDate(Yr,Mon,TimerDay,DOW);
  284.  
  285.   { If different, repaint window }
  286.   If TimerDay <> Day
  287.     Then AddInPaint(Wnd,DC,False);
  288.  
  289. End {AddInTimerTick};
  290.  
  291. {-----------------------------------------------}
  292.  
  293. { --- Proc called when button pressed --- }
  294.  
  295. Procedure AddInPressed(Wnd : HWnd; DC : HDC); Export;
  296.  
  297. Begin
  298.   { If shift or ctrl held, open sked+ & exit }
  299.   If (GetKeyState(vk_Shift) < 0) or (GetKeyState(vk_Control) < 0)
  300.     Then Begin
  301.            WinExec(CalendProgram,sw_ShowNormal);
  302.            Exit;
  303.          End;
  304.  
  305.   { Toggle the "show day-of-week" indicator when button pressed }
  306.   ShowDOW := Not ShowDOW;
  307.   AddInPaint(Wnd,DC,False);
  308. End {AddInPressed};
  309.  
  310. {-----------------------------------------------}
  311.  
  312. { --- Exit processing for Add-In --- }
  313.  
  314. Procedure AddInExit; Export;
  315.  
  316. Begin
  317. End {AddInExit};
  318.  
  319. {-----------------------------------------------}
  320.  
  321. { --- Clysbar queries Add-In about itself --- }
  322.  
  323. Procedure AddInAbout(Str1,Str2 : PChar;
  324.                      Var TheIcon : HIcon;
  325.                      Var TitleCol,TxCol,BkCol : TColorRef); Export;
  326.  
  327. Begin
  328.   StrCopy(Str1,'Calend V');
  329.   StrCat(Str1,MasterVer);
  330.   StrCopy(Str2,'A Page-per-Day Calendar'#13'⌐ 1992 - 1995 by clySmic Software.'#13'All Rights Reserved.');
  331.  
  332.   TheIcon := LoadIcon(hInstance,'about');
  333.  
  334.   TitleCol := RGB(0,0,255);
  335.   TxCol := RGB(0,0,128);
  336.   BkCol := RGB(192,192,192);
  337. End {AddInAbout};
  338.  
  339. {-----------------------------------------------}
  340.  
  341. { --- Clysbar queries Add-In whether it'll accept d'n'd --- }
  342.  
  343. Function AddInAcceptDrops : Boolean; Export;
  344.  
  345. Begin
  346.   AddInAcceptDrops := False;
  347. End {AddInAcceptDrops};
  348.  
  349. {-----------------------------------------------}
  350.  
  351. { --- Clysbar informs Add-In of a d'n'd drop --- }
  352.  
  353. Procedure AddInDrop(hDrop : THandle); Export;
  354.  
  355. Begin
  356. End {AddInDrop};
  357.  
  358. {-----------------------------------------------}
  359.  
  360. { --- Clysbar queries Add-In for Info Window text --- }
  361.  
  362. { Return a zero-length string if you don't want to chg the text }
  363.  
  364. Procedure AddInGetInfoWinTx(Tx : PChar); Export;
  365.  
  366. Var
  367.   OutsideTx : Boolean;
  368.  
  369. Begin
  370.   { Is text for outside or inside of button? Outside has more 'room,' so
  371.     note we can write longer descriptions }
  372.   If StrComp(Tx,'OUT') = 0
  373.     Then OutsideTx := True
  374.     Else OutsideTx := False;
  375.  
  376.   If GTxInBtn and (Not OutsideTx)
  377.     Then StrCopy(Tx,'')
  378.     Else Begin
  379.            FormIWDate;
  380.            StrCopy(Tx,IWDate);
  381.          End;
  382. End {AddInGetInfoWinTx};
  383.  
  384. {-----------------------------------------------}
  385.  
  386. Exports AddInInit         Index 1,
  387.         AddInPaint        Index 2,
  388.         AddInTimerNeeded  Index 3,
  389.         AddInTimerTick    Index 4,
  390.         AddInPressed      Index 5,
  391.         AddInExit         Index 6,
  392.         AddInAbout        Index 7,
  393.         AddInAcceptDrops  Index 8,
  394.         AddInDrop         Index 9,
  395.         AddInGetInfoWinTx Index 10;
  396.  
  397. Begin
  398. End.
  399.