summaryrefslogtreecommitdiff
path: root/maccaml/aboutbox.c
blob: 92cb19825532d81434999e510fd7849e9d009dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/***********************************************************************/
/*                                                                     */
/*                           Objective Caml                            */
/*                                                                     */
/*             Damien Doligez, projet Para, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 1997 Institut National de Recherche en Informatique et   */
/*  en Automatique.  All rights reserved.  This file is distributed    */
/*  under the terms of the GNU Library General Public License, with    */
/*  the special exception on linking described in file ../LICENSE.     */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

#include "main.h"

static WindowPtr aboutbox = NULL;
static UserItemUPP DrawAboutUPP = NULL;

#define kItemText 2

static pascal void DrawAbout (DialogPtr d, short item)
{
#pragma unused (item)
  WEHandle we = WinGetWE (d);

  Assert (we != NULL);
  WEUpdate (d->visRgn, we);
}

void OpenAboutBox (void)
{
  OSErr err;
  short itemtype;
  Handle item;
  Rect itemrect;
  LongRect lr;
  WEHandle we = NULL;
  WStatusH st = NULL;
  Handle txt = NULL, copr = NULL;
  TextStyle ts;

  if (DrawAboutUPP == NULL) DrawAboutUPP = NewUserItemProc (DrawAbout);

  if (aboutbox != NULL){
    SelectWindow (aboutbox);
  }else{
    aboutbox = GetNewDialog (kDialogAbout, NULL, (WindowPtr) -1L);
    if (aboutbox == NULL){
      err = memFullErr;
      goto failed;
    }
    SetPort (aboutbox);

    err = WinAllocStatus (aboutbox);
    if (err != noErr) goto failed;

    st = WinGetStatus (aboutbox);
    Assert (st != NULL);
    (*st)->kind = kWinAbout;

    GetDialogItem (aboutbox, kItemText, &itemtype, &item, &itemrect);
    SetDialogItem (aboutbox, kItemText, itemtype, (Handle) DrawAboutUPP, &itemrect);
    WERectToLongRect (&itemrect, &lr);
    err = WENew (&lr, &lr, 0, &we);
    if (err != noErr) goto failed;

    (*st)->we = we;

    GetFNum ("\pGeneva", &ts.tsFont);
    ts.tsSize = 10;
    err = WESetStyle (weDoFont + weDoSize, &ts, we);
    if (err != noErr) goto failed;

    txt = GetResource ('TEXT', kAboutText1);
    err = ResError (); if (err != noErr){ err = noErr; goto failed; }
    DetachResource (txt);

    copr = GetResource ('TEXT', kAboutText2);
    err = ResError ();
    if (err == noErr){
      HLock (copr);
      err = HandAndHand (copr, txt);
      /* ignore errors */
      HUnlock (copr);
      ReleaseResource (copr);
      copr = NULL;
    }

    err = WEUseText (txt, we);
    if (err != noErr) goto failed;
    err = WECalText (we);
    if (err != noErr) goto failed;

    WEFeatureFlag (weFReadOnly, weBitSet, we);

    return;

    failed:
    if (copr != NULL) DisposeHandle (copr);
    if (txt != NULL) DisposeHandle (txt);
    if (we != NULL) WEDispose (we);
    if (st != NULL) DisposeHandle ((Handle) st);
    if (aboutbox != NULL) DisposeWindow (aboutbox);
    aboutbox = NULL;
    ErrorAlertGeneric (err);
  }
}

void CloseAboutBox (WindowPtr w)
{
  WStatusH st = WinGetStatus (w);
  WEHandle we = WinGetWE (w);

  Assert (w == aboutbox);

  Assert (we != NULL);
  WEDispose (we);
  Assert (st != NULL);
  DisposeHandle ((Handle) st);
  Assert (w != NULL);
  DisposeDialog (w);
  aboutbox = NULL;
}