OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
hlpmanag.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class THelpFileManager & THelpContext
7//----------------------------------------------------------------------------
8
9#include <owl/pch.h>
10
11#include <owl/hlpmanag.h>
12#include <owl/applicat.h>
13#include <owl/window.h>
14#include <owl/framewin.h>
15#include <owl/gadgetwi.h>
16#include <owl/template.h>
17
18#if !defined(OWL_HLPMANAG_RH)
19# include <owl/hlpmanag.rh>
20#endif
21
22#if defined(__BORLANDC__)
23# pragma option -w-ccc // Disable "Condition is always true/false"
24#endif
25
26namespace owl {
27
29
30static tchar HtmlHelpDllName[] = _T("HHCTRL.OCX");
31
33:
34 TModule(HtmlHelpDllName, true, true, false), // shouldLoad, mustLoad and !addToList
35 DllCanUnloadNow(*this, "DllCanUnloadNow"),
36 DllGetClassObject(*this, "DllGetClassObject"),
38 HtmlHelp(*this, "HtmlHelpW")
39#else
40 HtmlHelp(*this, "HtmlHelpA")
41#endif
42{
43}
44
46{
47 cbStruct = sizeof(HH_POPUP);
48 hinst = nullptr;
49 idString = id;
50 pszText = nullptr;
51 pt = TPoint(-1,-1);
52 clrForeground = static_cast<COLORREF>(-1); //JJH added static casts
53 clrBackground = static_cast<COLORREF>(-1);
54 rcMargins = TRect(-1,-1,-1,-1);
55 pszFont = nullptr;
56}
57
58void
60{
62 dwStyles |= style;
63}
64
65void
71
72void
78
79void
85
86//
87/// Constructor. Saves the name of the help file and creates the global context
88/// table.
89//
91:
92 UseHTMLHelp(false),
93 WinToHTML(true),
94 HelpCursor(nullptr),
95 ContextHelp(false),
96 HelpState(false),
97 LastParent(nullptr)
98{
101}
102
103//
104/// Deletes the allocated context table.
105//
111
112//
113/// Called by EvHelp() to activate the help file with the help context ID.
114//
115void
117{
121 if(UseHTMLHelp){
122 if (app)
123 HelpState = ToBool(HtmlHelp(app->GetMainWindow(), GetHelpFile().c_str(),
124 helpCmd, helpFileContextId) != nullptr);
125 else
127 helpCmd, helpFileContextId) != nullptr);
128 }
129 else{
130 if (app)
131 HelpState = ToBool(app->GetMainWindow()->WinHelp(GetHelpFile().c_str(),
133 else
134 HelpState = ToBool(::WinHelp(nullptr, GetHelpFile().c_str(),
136 }
137}
138
139//
140/// Deactivates the help.
141//
142void
144{
146 if(UseHTMLHelp){
147 if (app)
148 HtmlHelp(app->GetMainWindow(), GetHelpFile().c_str(), HELP_QUIT, 0);
149 else
150 HtmlHelp(nullptr, GetHelpFile().c_str(), HELP_QUIT, 0);
151 }
152 else{
153 if (app)
154 app->GetMainWindow()->WinHelp(GetHelpFile().c_str(), HELP_QUIT, 0);
155 else
156 ::WinHelp(nullptr, GetHelpFile().c_str(), HELP_QUIT, 0);
157 }
158}
159
160//
161// Support for nwe HTML Help
162//
163HWND
165{
166 // translate uCommand into HTML command
167 uint command = uCmd;
168 if(WinToHTML){
169 switch(uCmd){
170 case HELP_FINDER:
172 break;
173 case HELP_CONTENTS: //== HELP_INDEX
175 break;
176 case HELP_WM_HELP:
178 break;
179 case HELP_CONTEXTMENU:
181 break;
182 case HELP_QUIT:
184 break;
185 case HELP_CONTEXTPOPUP: {
186//-----------------------
187//Start Ole Änderung 02.04.2002
188// command = HH_TP_HELP_CONTEXTMENU;
190 if(THtmlHelp::IsAvailable()){
191 if(LastHit == TPoint(-1, -1))
192 HtmlHelp(GetWindowPtr(GetDesktopWindow()), lpszHelp, HH_HELP_CONTEXT,data) ;
193 else
194 {
195 HH_POPUP hPop; // HTML Help popup structure
196 memset(&hPop, 0, sizeof(hPop));
197 hPop.cbStruct = sizeof(hPop);
198 hPop.clrBackground = -1;
199 hPop.clrForeground = -1;
200 hPop.rcMargins.left = -1;
201 hPop.rcMargins.bottom = -1;
202 hPop.rcMargins.right = -1;
203 hPop.pt = LastHit;
204 hPop.idString = static_cast<UINT>(data);
205 hPop.pszText = nullptr;
206 hPop.pszFont = nullptr;
207
208 const HWND w = wnd ? wnd->GetHandle() : nullptr;
209 return THtmlHelp::Dll()->HtmlHelp(w, lpszHelp, command, reinterpret_cast<DWORD_PTR>(&hPop));
210 }
211
212// if(wnd)
213// return THtmlHelp::Dll()->HtmlHelp(*wnd,lpszHelp,command,data);
214// else
215// return THtmlHelp::Dll()->HtmlHelp(0, lpszHelp,command,data);
216//Ende Ole Änderung 02.04.2002
217//-----------------------
218 }
219 return nullptr;
220 }
221 }
222 }
223 if(THtmlHelp::IsAvailable()){
224 if(wnd)
225 return THtmlHelp::Dll()->HtmlHelp(*wnd,lpszHelp,command,data);
226 else
227 return THtmlHelp::Dll()->HtmlHelp(nullptr, lpszHelp,command,data);
228 }
229 return nullptr;
230}
231
232//
233/// Changes the name of the help file.
234//
235void
237{
239 UseHTMLHelp = false;
240 LPCTSTR ptr = _tcsrchr(HelpFileName.c_str(),_T('.'));
241 if(ptr && _tcsicmp(ptr, _T(".chm"))==0)
242 UseHTMLHelp = true;
243}
244
246 EV_COMMAND(CM_CONTEXTHELP, CmContextHelp),
252
253//
254//
255//
256void
257THelpFileManager::SetHelpCursor()
258{
259 if(!HelpCursor){
261 if(app)
262 HelpCursor = new TCursor(*app, TResId(IDC_HELPCURSOR));
263 }
264 ::SetCursor(*HelpCursor);
265}
266
267//
268//
269//
270void
276
277//
278//
279//
280void
285
286//
287//
288//
289void
291{
293 if(!LastParent)
294 return;
295 LastParent->ScreenToClient(LastHit); // TWindow
297 HELPINFO Info;
298 Info.cbSize = sizeof(Info);
299 Info.MousePos = LastHit;
300
301 if(hWnd){
303 if(gwin){
304 TGadget* gd = gwin->GadgetFromPoint(LastHit);
305 if(gd){
306 Info.iContextType = HELPINFO_MENUITEM;
307 Info.iCtrlId = gd->GetId();
308 EvHelp(Info);
309 }
310 return;
311 }
312 }
313 Info.iContextType = HELPINFO_WINDOW;
314 Info.dwContextId = 0;
315
316 // If the click wasn't on one of the controls, open Help for dialog.
317 if (hWnd == nullptr || hWnd == LastParent->GetHandle()){
318 Info.iContextType = HELPINFO_MENUITEM;
319 Info.iCtrlId = IDHELP;
320 Info.hItemHandle = LastParent->GetHandle();
321 }
322 else{
323 Info.iCtrlId = ::GetDlgCtrlID(hWnd);
324 Info.hItemHandle = hWnd;
325 }
326 EvHelp(Info);
327}
328
329//
330/// Event handler for the WM_HELP message.
331//
332void
334{
336 bool success = false;
338
339 if (hi.iContextType == HELPINFO_MENUITEM){
342 }
343 else if (hi.iContextType == HELPINFO_WINDOW)
344 success = GetHelpContextFromControl(context, hi.iCtrlId, static_cast<HWND>(hi.hItemHandle));
345
346 LastHit = hi.MousePos;
347 if (::GetKeyState(VK_F1) < 0 && ::GetKeyState(VK_SHIFT) < 0)
348 {
349 TWindow* wnd = context.GetWindow();
350 TWindow* child = wnd->ChildWithId(hi.iCtrlId);
351 LastHit = TPoint(wnd->GetWindowAttr().X + child->GetWindowAttr().X, wnd->GetWindowAttr().Y + child->GetWindowAttr().Y);
352 }
353 else if(::GetKeyState(VK_F1) < 0)
354 LastHit = TPoint(-1, -1);
355
356 if (success)
357 ActivateHelp(context.GetWindow(), context.GetHelpFileContextId(), hlpCmd);
358}
359
360//
361//
362//
363bool
365{
366 if (msg.message == WM_COMMAND) {
367 // help command from menu or from gadget from "what this?" for gadget
368 if (ContextHelp || (::GetKeyState(VK_F1) < 0)) {
369 ContextHelp = false;
370 HELPINFO Info;
371 Info.cbSize = sizeof(Info);
372 Info.iContextType = HELPINFO_MENUITEM;
373 Info.iCtrlId = static_cast<int>(msg.wParam);
374 Info.dwContextId = 0;
375 EvHelp(Info);
376 return true;
377 }
378 }
379 else{
380 switch (msg.message) {
381 case WM_KEYDOWN :
382 if (msg.wParam == VK_F1) {
383 // If the Shift/F1 then set the help cursor and turn on the modal help state.
384 if (::GetKeyState(VK_SHIFT) < 0 && !ContextHelp) {
386 return true; // Gobble up the message.
387 }
388 }
389 else {
390 if (ContextHelp && (msg.wParam == VK_ESCAPE)) {
391 ContextHelp = false;
393 if (app)
394 app->GetMainWindow()->SetCursor(nullptr, IDC_ARROW); //?????????????????
395 return true; // Gobble up the message.
396 }
397 }
398 break;
399
400 case WM_MOUSEMOVE :
401 case WM_NCMOUSEMOVE :
402 if(ContextHelp){
404 return true; // Gobble up the message.
405 }
406 break;
407
408 case WM_INITMENU :
409 if(ContextHelp) {
411 return true; // Gobble up the message.
412 }
413 break;
414
415 case WM_ENTERIDLE :
416 if(msg.wParam == MSGF_MENU)
417 if (GetKeyState(VK_F1) < 0) {
418 ContextHelp = true;
420 if (app)
421 app->GetMainWindow()->PostMessage(WM_KEYDOWN, VK_RETURN, 0L);
422 return true; // Gobble up the message.
423 }
424 break;
425
426 default :
427 ;
428 } // End of switch
429 }
430 // Continue normal processing.
431 return false;
432}
433
434//
435/// Return true if the control id is the same as the context entry's control id.
436//
437static bool
438MatchControlId(const THelpContext& context, int controlId, HWND hwnd)
439{
440 if (context.GetControlContextId() == controlId &&
441 context.GetWindow() && context.GetWindow()->IsChild(hwnd)) {
442 return true;
443 }
444 return false;
445}
446
447//
448/// Returns true if a match for the control ID was found.
449//
450bool
452 int controlId, HWND hwnd) const
453{
454 // for each item in the context table
455 //
456 for(TContextListIterator iterator(*ContextTable); iterator; iterator++){
457 context = iterator.Current();
458
459 // try to match the control id
460 //
462 THelpContext* indirect = reinterpret_cast<THelpContext*>(context.GetWindow());
464 if (MatchControlId(*indirect, controlId, hwnd)) {
465 context = *indirect;
466 return true;
467 }
468 indirect++;
469 }
470 }
471 else if (MatchControlId(context, controlId, hwnd))
472 return true;
473 }
474 return false;
475}
476
477//
478/// Return true if the menu item identifier matches a context entry's menu
479/// item identifier.
480//
481static bool
482MatchMenuId(const THelpContext& context, int menuId)
483{
484 if (context.GetMenuContextId() == menuId) {
485 return true;
486 }
487 return false;
488}
489
490//
491/// Returns true if a match for the menu item ID was found.
492//
493bool
495{
496 // for each item in the context table
497 //
498 for (TContextListIterator iterator(*ContextTable); iterator; iterator++) {
499 context = iterator.Current();
500
501
502 // try to match the menu item identifier
503 //
505 THelpContext* indirect = reinterpret_cast<THelpContext*>(context.GetWindow());
507 if (MatchMenuId(*indirect, menuId)) {
508 context = *indirect;
509 return true;
510 }
511 indirect++;
512 }
513 }
514 else if (MatchMenuId(context, menuId))
515 return true;
516 }
517 return false;
518}
519
520//
521/// Adds an entry into the global context table.
522//
523void
525{
526 ContextTable->Add(THelpContext(window, helpId, menuId, controlId));
527}
528
529static bool
530WindowsEqual(const THelpContext& context, void* ptr)
531{
532 TWindow* targetWindow = static_cast<TWindow*>(ptr);
533 if (context.GetWindow() == targetWindow)
534 return true;
535 return false;
536}
537
538//
539/// Removes all the entries in the context table for the window.
540//
541void
543{
544 THelpContext* context = ContextTable->FirstThat(WindowsEqual, window);
545 while (context) {
546 ContextTable->DetachItem(*context);
547 context = ContextTable->FirstThat(WindowsEqual, window);
548 }
549 if (ContextTable->Empty())
551}
552
553//
554/// Default constructor that initializes every data member to zero.
555//
557:
558 Window(nullptr),
559 HelpFileContextId(0),
560 MenuContextId(0),
561 ControlContextId(0)
562{
563}
564
565//
566/// Convenient constructor to initialize the context entry with the
567/// proper ids.
568//
570:
571 Window(window),
572 HelpFileContextId(helpId),
573 MenuContextId(menuId),
574 ControlContextId(controlId)
575{
576}
577
578//
579/// Makes a copy of the context entry.
580//
582{
583 *this = other;
584}
585
586//
587// Do nothing.
588//
592
593//
594/// Makes a copy of the context entry.
595//
598{
599 HelpFileContextId = other.GetHelpFileContextId();
600 MenuContextId = other.GetMenuContextId();
601 ControlContextId = other.GetControlContextId();
602 Window = other.GetWindow();
603 return *this;
604}
605
606//
607/// Returns true if the context entries match.
608//
609bool
611{
612 return Window == other.GetWindow() &&
613 HelpFileContextId == other.GetHelpFileContextId() &&
614 MenuContextId == other.GetMenuContextId() &&
615 ControlContextId == other.GetControlContextId();
616}
617//
618//
619//
620bool
622{
623 return HelpFileContextId < other.GetHelpFileContextId();
624}
625
626} // OWL namespace
627/* ========================================================================== */
628
Definition of class TApplication.
#define PRECONDITION(condition)
Definition checks.h:227
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
Definition applicat.h:141
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
TCursor, derived from TGdiBase, represents the GDI cursor object class.
Definition gdiobjec.h:730
TEventHandler is a base class from which you can derive classes that handle messages.
Definition eventhan.h:162
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
Derived from TWindow, TGadgetWindow maintains a list of tiled gadgets for a window and lets you dynam...
Definition gadgetwi.h:122
THelpContext is a class that maintains information about a menu item id and a child control id with a...
Definition hlpmanag.h:116
bool operator==(const THelpContext &) const
Returns true if the context entries match.
Definition hlpmanag.cpp:610
bool operator<(const THelpContext &) const
Definition hlpmanag.cpp:621
THelpContext()
Default constructor that initializes every data member to zero.
Definition hlpmanag.cpp:556
THelpContext & operator=(const THelpContext &)
Makes a copy of the context entry.
Definition hlpmanag.cpp:597
THelpFileManager, which is designed to be a mix-in for TApplication, uses the global context table.
Definition hlpmanag.h:154
virtual bool ProcessHelpMsg(MSG &msg)
Definition hlpmanag.cpp:364
HWND HtmlHelp(TWindow *, LPCTSTR lpszHelp, uint hlpCmd, DWORD_PTR data)
Definition hlpmanag.cpp:164
TBaseList< THelpContext > TContextList
Definition hlpmanag.h:197
void RemoveContextInfo(TWindow *)
Removes all the entries in the context table for the window.
Definition hlpmanag.cpp:542
void EvHelp(const HELPINFO &)
Event handler for the WM_HELP message.
Definition hlpmanag.cpp:333
void AddContextInfo(TWindow *, int helpId, int menuId, int controlId)
Adds an entry into the global context table.
Definition hlpmanag.cpp:524
virtual ~THelpFileManager()
Deletes the allocated context table.
Definition hlpmanag.cpp:106
virtual void SetHelpCursor()
Definition hlpmanag.cpp:257
THelpFileManager(const tstring &helpFileName)
Constructor.
Definition hlpmanag.cpp:90
bool GetHelpContextFromMenu(THelpContext &, int menuId) const
Returns true if a match for the menu item ID was found.
Definition hlpmanag.cpp:494
virtual void DeactivateHelp()
Deactivates the help.
Definition hlpmanag.cpp:143
tstring GetHelpFile() const
Returns the name of the help file.
Definition hlpmanag.h:318
virtual void ActivateHelp(TWindow *, int helpFileContextId, uint hlpCmd=HELP_CONTEXT)
Called by EvHelp() to activate the help file with the help context ID.
Definition hlpmanag.cpp:116
TContextList * ContextTable
Definition hlpmanag.h:199
void SetHelpFile(const tstring &helpFileName)
Changes the name of the help file.
Definition hlpmanag.cpp:236
void CeContextHelp(TCommandEnabler &ce)
Definition hlpmanag.cpp:281
bool GetHelpContextFromControl(THelpContext &, int controlId, HWND ctrl) const
Returns true if a match for the control ID was found.
Definition hlpmanag.cpp:451
THlpPopup(uint id=0)
Definition hlpmanag.cpp:45
void SetWindowsPos(const TRect &rect)
Definition hlpmanag.cpp:80
void SetToolBarFlags(int flags)
Definition hlpmanag.cpp:73
void SetProperties(int prop)
Definition hlpmanag.cpp:66
void SetStyle(int style)
Definition hlpmanag.cpp:59
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
HWND ChildWindowFromPoint(const TPoint &point) const
Determines which of the child windows contains the point specified in TPoint.
Definition window.h:2238
void ScreenToClient(TPoint &point) const
Uses the screen coordinates specified in point to calculate the client window's coordinates and then ...
Definition window.h:2192
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
#define _tcsicmp
Definition cygwin.h:76
#define _T(x)
Definition cygwin.h:51
#define _tcsrchr
Definition cygwin.h:86
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Definition of class TFrameWindow.
Definition of TGadgetList, TGadgetWindow & TGadgetWindowFont A list holding gadgets,...
Declares THelpContext and THelpFileManager.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_OWLHELPHIT
Definition hlpmanag.cpp:250
TWindow * GetWindowPtr(HWND, const TApplication *)
Raw function to retrieve a TWindow pointer given an HWND from the a given app, or any app (app==0).
Definition window.cpp:1557
bool IsLastIndirectContext(const THelpContext &context)
Return true if this entry is the last entry.
Definition hlpmanag.h:305
char tchar
Definition defs.h:77
bool ToBool(const T &t)
Definition defs.h:291
bool IsIndirectHelpContext(const THelpContext &context)
Return true if the context entry is a pointer to another table.
Definition hlpmanag.h:292
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
EV_WM_HELP
Definition hlpmanag.cpp:249
STDAPI DllCanUnloadNow()
OLE 2.0 entry point for checking if DLL has no clients and can be unloaded.
Definition ocreg.cpp:543
STDAPI DllGetClassObject(const GUID &clsid, const GUID &iid, void **retObj)
OLE 2.0 entry point for obtaining a class factory for a particular CLSID Don't let any exceptions blo...
Definition ocreg.cpp:524
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Definition of container classes used and made available by OWL.
Base window class TWindow definition, including HWND encapsulation.
#define EV_COMMAND_ENABLE(id, method)
Response table entry for enabling a command.
Definition windowev.h:193
#define EV_COMMAND(id, method)
Response table entry for a menu/accelerator/push button message.
Definition windowev.h:171