skyrope-mit-merge-hell-20040226
[openafs.git] / src / WINNT / afsapplib / al_help.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include <WINNT/afsapplib.h>
16
17
18 /*
19  * DEFINITIONS ______________________________________________________________
20  *
21  */
22
23 typedef struct 
24    {
25    BOOL fInUse;
26    int idd;
27    DWORD *adwContext;
28    int idhOverview;
29    } DIALOGHELP, *LPDIALOGHELP;
30
31
32 /*
33  * VARIABLES ________________________________________________________________
34  *
35  */
36
37 static TCHAR g_szHelpfile[ MAX_PATH ] = TEXT("");
38
39 static DIALOGHELP *g_adh = NULL;
40 static size_t g_cdh = 0;
41
42
43 /*
44  * ROUTINES _________________________________________________________________
45  *
46  */
47
48 void AfsAppLib_RegisterHelpFile (LPTSTR pszFilename)
49 {
50    if (pszFilename)
51       lstrcpy (g_szHelpfile, pszFilename);
52    else
53       g_szHelpfile[0] = TEXT('\0');
54 }
55
56
57 void AfsAppLib_RegisterHelp (int idd, DWORD *adwContext, int idhOverview)
58 {
59    for (size_t ih = 0; ih < g_cdh; ++ih)
60       {
61       if (!g_adh[ ih ].fInUse)
62          continue;
63       if (g_adh[ ih ].idd == idd)
64          {
65          g_adh[ ih ].adwContext = adwContext;
66          g_adh[ ih ].idhOverview = idhOverview;
67          return;
68          }
69       }
70    for (ih = 0; ih < g_cdh; ++ih)
71       {
72       if (!g_adh[ ih ].fInUse)
73          break;
74       }
75    if (ih == g_cdh)
76       {
77       (void)REALLOC (g_adh, g_cdh, 1+ih, 16);
78       }
79    if (ih < g_cdh)
80       {
81       g_adh[ ih ].fInUse = TRUE;
82       g_adh[ ih ].idd = idd;
83       g_adh[ ih ].adwContext = adwContext;
84       g_adh[ ih ].idhOverview = idhOverview;
85       }
86 }
87
88
89 BOOL AfsAppLib_HandleHelp (int idd, HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
90 {
91    BOOL rc = FALSE;
92    size_t ih;
93
94    switch (msg)
95       {
96       case WM_COMMAND:
97          switch (LOWORD(wp))
98             {
99             case IDHELP:
100                for (ih = 0; ih < g_cdh; ++ih)
101                   {
102                   if (idd == g_adh[ ih ].idd)
103                      break;
104                   }
105                if (ih < g_cdh)
106                   {
107                   if (g_szHelpfile)
108                      WinHelp (hDlg, g_szHelpfile, HELP_CONTEXT, g_adh[ ih ].idhOverview);
109                   rc = TRUE;
110                   }
111                break;
112             }
113          break;
114
115       case WM_HELP:
116          LPHELPINFO lphi;
117          for (ih = 0; ih < g_cdh; ++ih)
118             {
119             if (idd == g_adh[ ih ].idd)
120                break;
121             }
122
123          if ( (ih == g_cdh) ||
124               ((lphi = (LPHELPINFO)lp) == NULL) ||
125               (lphi->hItemHandle == NULL) ||
126               (lphi->hItemHandle == hDlg) )
127             {
128             PostMessage (hDlg, WM_COMMAND, (WPARAM)MAKELONG(IDHELP,BN_CLICKED), (LPARAM)GetDlgItem (hDlg, IDHELP));
129             }
130          else
131             {
132             if (g_szHelpfile)
133                WinHelp ((HWND)(lphi->hItemHandle), g_szHelpfile, HELP_WM_HELP, (DWORD)g_adh[ ih ].adwContext);
134             }
135
136          rc = TRUE;
137          break;
138       }
139
140    return rc;
141 }
142