uiinfhlp.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:41k
源码类别:

操作系统开发

开发平台:

Visual C++

  1.         TITLE   uiinfhlp.asm - interface routines for new help engine.
  2. ;***
  3. ;uiinflp.asm
  4. ;
  5. ;       Copyright <C> 1985-1988, Microsoft Corporation
  6. ;
  7. ;Purpose:
  8. ;       Interface routines for the new help system.
  9. ;
  10. ;
  11. ;*******************************************************************************
  12.         .xlist
  13.         include version.inc
  14.         .list
  15.         UIINFHLP_ASM = ON
  16.         include cw/version.inc
  17.         include cw/windows.inc
  18.         include cw/edityp.inc
  19.         IncludeOnce architec
  20.         Include     help.inc
  21.         IncludeOnce qbimsgs
  22.         IncludeOnce ui
  23.         IncludeOnce uiint
  24.         IncludeOnce uimenu
  25.         IncludeOnce uinhelp
  26. assumes DS,DATA
  27. assumes ES,DATA
  28. assumes SS,DATA
  29.         subttl  DATA segment definitions.
  30.         page
  31. sBegin  DATA
  32.         externB HelpFlags
  33.         globalB fMessageBox,0,1         ; are we in a message box?
  34.         externW efHelp                  ; Editmgr structure for Help Wnd.
  35.         externW oCurTopic               ; offset to the current topic
  36.         globalW iStaticHelpTopic,0,1    ; High word of NC during searches
  37.         externB b$Buf1                  ; FILNAML-sized buffer
  38.         externB b$Buf2
  39.         externW iFileSize               ; Size of current help topic
  40.         externW iCurRequestLine
  41.         externW rgLineAttr              ; static attribute buffer
  42.         externB fHelpAlloc
  43.         HtSpot  EQU     b$Buf2          ; Static HotSpot structure
  44. sEnd    DATA
  45.         externFP GetEditMgrState
  46.         externFP EditFilterWndProc
  47.         externFP HelpSzContext
  48.         externFP HelpHlNext
  49.         externFP HelpNcPrev
  50.         externFP HelpGetLineAttr
  51.         externFP HelpGetLine
  52.         externFP HelpNcNext
  53. sBegin  UI
  54. assumes CS,UI
  55.         externNP toupper
  56.         externNP GotoBookMark
  57.         externNP SetBookMark
  58.         externNP GetInitialPos
  59.         externNP GetNextNc
  60.         externNP SzSrchExcl
  61.         externNP AppendBuf
  62.         externNP CalcNc
  63.         externNP MoveCursorPwnd
  64.         externNP SizeHelpContext
  65. ;***
  66. ;DisplayHlpGeneric - Display either VarHelp or EngineHelp on screen
  67. ;
  68. ;Purpose:
  69. ;       Will deturmine the type of help specified and display it in
  70. ;       the help window.  It is expected to call this routine after
  71. ;       calling RetrieveHelpHistory, as its output parameters identically
  72. ;       match our input parameters.
  73. ;
  74. ;Entry:
  75. ;       DX:AX   - Help Topic (NC or Var Help ID)
  76. ;       CL      - Flags (EI_VARHELP only)
  77. ;                       0 => Engine help
  78. ;                      ~0 => Variable help
  79. ;
  80. ;Exit:
  81. ;       AL = 0    all ok
  82. ;       AL <> 0   failure (returns Error Code)
  83. ;****
  84. cProc   DisplayHlpGeneric,<NEAR>
  85. cBegin
  86.         cCall   DisplayHlpWndNc         ; display the new topic
  87.         ;AL = 0 if succeeded, error code otherwise
  88. DisplayHlpGeneric_Exit:
  89. cEnd
  90. ;***
  91. ;NextHotLink - Go to next hot link
  92. ;
  93. ;Purpose:
  94. ;       This routine will move the cursor to the next hot link in the
  95. ;       current topic.  Will wrap around the proper end of the help topic
  96. ;       to check for hot links if needed.
  97. ;
  98. ;Entry:
  99. ;       cLead : parameter to pass to HelpHlNext
  100. ;
  101. ;Exit:
  102. ;       None.
  103. ;
  104. ;****
  105. cProc   NextHotLink,<NEAR>,<SI,DI>
  106. parmW   cLead
  107. cBegin
  108.         ; This routine is only called when the help window is open
  109.         ; and valid, thus we can assert HLP_GOTBUF and oCurTopic.
  110.         DbAssertTst HelpFlags,ne,HLP_GOTBUF,UI,<NextHotLink:Buffers not initialized>
  111.         DbChk   HoldBuf2                ; lock down the HotSpot
  112.         ;Get current line#/column number
  113.         mov     ax,EfHelp.EF_ipCur_ob   ; get the current column
  114.         inc     ax                      ; make it 1 relative
  115.         mov     HtSpot.colHS,ax         ; save it for HelpHlNext
  116.         mov     ax,EfHelp.EF_ipCur_oln  ; current line #
  117.         inc     ax                      ; make it 1 relative
  118.         mov     HtSpot.lineHS,ax        ; save line number for help engine
  119.         xor     di,di                   ; first time through
  120. DbAssertRel     oCurTopic,ne,0,UI,<NextHotLink:oCurTopic invalid>
  121.         mov     si,oCurTopic            ; get ptr to current topic
  122. HotSpotRetry:
  123.         lea     bx,[si].bdlHelpText.BDL_seg ; BX = handle of text seg
  124.         xor     ax,ax                   ; ax = offset of text
  125.         mov     cx,OFFSET DGROUP:HtSpot ; cx = offset of HotSPot
  126.         push    HtSpot.lineHS           ; save row and column of hot spot
  127.         push    HtSpot.colHS
  128.         cCall   HelpHlNext,<cLead,BX,AX,DS,CX>
  129.         pop     bx                      ; restore row and column of old hot spot
  130.         pop     cx
  131.         or      ax,ax                   ; did we get a hot linK?
  132.         je      NextHotLink_Retry       ; no, go complain
  133.         mov     ax,di                   ; save old loop counter
  134.         inc     di                      ; one more time through loop
  135.         or      ax,ax                   ; first time through?
  136.         jne     MoveCursorToHotLink     ; no, it is a real hot link
  137.         cmp     cx,HtSpot.lineHS        ; on the same row?
  138.         jne     MoveCursorToHotLink     ; no, must be a real hot link
  139.         cmp     bx,HtSpot.colHS         ; old column in current hot spot?
  140.         jl      MoveCursorToHotLink     ; no, must be a real hot link
  141.         mov     ax,HtSpot.ecolHS        ; AX = ending column of hot spot
  142.         cmp     bx,ax                   ; old column in current hot spot
  143.         ja      MoveCursorToHotLink     ; no, must be a real hot link
  144.         inc     ax                      ; try again after the hot spot
  145.         mov     HtSpot.colHS,ax         ; set position
  146.         jmp     HotSpotRetry            ; and try again
  147. NextHotLink_Beep:
  148.         cCall   CowMoo                  ; beep the speaker
  149.         jmp     short NextHotLink_Exit  ; and leave.
  150. NextHotLink_Retry:
  151.         cmp     di,1                    ; Have we already wrapped around?
  152.         ja      NextHotLink_Beep        ; yes, nothing to find
  153.         mov     di,2                    ; set wrapped flag
  154.         mov     ax,1                    ; assume wrapping backwards
  155.         mov     HtSpot.lineHS,ax        ; set line + col position
  156.         mov     HtSpot.colHS,ax
  157.         test    cLead,8000H             ; forward (+) or backwards (-)?
  158.         jz      HotSpotRetry            ; we assumed right
  159.         mov     ax,iFileSize            ; get last line number
  160.         mov     HtSpot.lineHS,ax
  161.         mov     HtSpot.colHS,-1         ; column position FFFF
  162.         jmp     HotSpotRetry
  163. MoveCursorToHotLink:
  164.         ;Move the cursor to the position specified in the HotSpot structure
  165.         mov     ax,HtSpot.lineHS        ; get the context relative row
  166.         dec     ax                      ; make it 0 relative
  167.         mov     cx,OFFSET DGROUP:wndHelp
  168.         mov     bx,HtSpot.colHS         ; get the context relative column
  169.         dec     bx                      ; make it 0 relative
  170.         cCall   MoveCursorPwnd,<cx,ax,bx> ; move cursor to hotspot
  171. NextHotLink_Exit:
  172.         DbChk   FreeBuf2                ; release the HotSpot
  173. cEnd
  174. ;***
  175. ;HelpBack - Backup one level of help (if possible)
  176. ;
  177. ;Purpose:
  178. ;       Implements ALT-F1.  The user asked us to go to the help topic
  179. ;       that was previously shown.
  180. ;
  181. ;
  182. ;       NOTE: SLIME: this routine uses iStaticHelpTopic for a temporary
  183. ;                    Dgroup storage location.  This should cause no problems,
  184. ;                    as HelpBack and searching are mutually exclusive.
  185. ;
  186. ;Entry:
  187. ;       None
  188. ;
  189. ;Exit:
  190. ;       None
  191. ;
  192. ;Uses:
  193. ;       Per Convention
  194. ;
  195. ;****
  196. cProc   HelpBack,<PUBLIC, NEAR>,<SI,DI>
  197. cBegin
  198. ;There are two cases to handle:
  199. ;       1) If the cursor is not at the start of a topic, move to start of topic
  200. ;          (note: the start of the topic is 0,0 and (if visible on the screen)
  201. ;          the first hot link.
  202. ;       2) If the cursor is at the start of a topic, move to previous topic
  203. ;
  204. ;General Algorithm when EI_VARHELP is turned on
  205. ;       Get Last topic from help history (should be displayed topic)
  206. ;       save topic
  207. ;       if (cursor not at start-of-topic)
  208. ;           Display Saved Topic  (will force cursor to start of topic)
  209. ;       else
  210. ;           while (New topic not displayed OK)
  211. ;               if (Topic Exists)
  212. ;                   Get Last topic from help history (topic to be displayed)
  213. ;                   Try to Display Topic
  214. ;               else
  215. ;                   Display Saved Topic
  216. ;
  217. ; We do not call HelpStart, as there is no reason to start the help system
  218. ; if it is not already started.  No Help => No Help Back => exit with error
  219. ;
  220.         test    HelpFlags,HLP_GOTBUF    ; are we initialized?
  221.         jne     Initialized             ; yes, see if we can get history
  222. HelpBack_Err:
  223.         cCall   CowMoo                  ; beep the speaker
  224. DJMP    jmp     short HelpBack_Exit     ; and return
  225. Initialized:
  226.         cCall   RetrieveHelpHistory     ; get the currently displayed item
  227.         jcxz    HelpBack_Err            ; no current topic? exit
  228.                                         ; (possible if no help ask for yet)
  229.         mov     si,dx                   ; set SI:DI = context info.
  230.         mov     di,ax
  231.         ;Test for cursor at begining of topic
  232.         xor     ax,ax                   ; 0 to compare against
  233.         cmp     fHelpVisible,al         ; help window visible?
  234.         je      CurrentTopic            ; no, goto current topic
  235.         cmp     EfHelp.EF_ipCur_ob,ax   ; at column 0?
  236.         jne     CheckHotLink            ; no, goto initial position
  237.         cmp     EfHelp.EF_ipCur_oln,ax  ; on first line?
  238.         je      PreviousTopic           ; yes, goto previous topic
  239. CheckHotLink:
  240.         cCall   GetInitialPos           ; (DX,AX) is initial cursor position
  241.         cmp     EfHelp.EF_ipCur_ob,ax   ; in the right column?
  242.         jne     CurrentTopic            ; no, redisplay current topic
  243.         cmp     EfHelp.EF_ipCur_oln,dx  ; in the right row?
  244.         jne     CurrentTopic            ; no, redisplay current topic
  245. PreviousTopic:
  246.         cCall   RetrieveHelpHistory     ; get the item to goto
  247.         jcxz    CurrentTopicBeep        ; none, beep and exit (CX = 0)
  248.         cCall   DisplayHlpWndNc         ; display the topic
  249.         cmp     al,HELP_HANDLED         ; did we get an error?
  250.         je      CurrentTopic            ; yes, try to clean up and exit
  251.         or      al,al                   ; did we succeed?
  252.         jne     PreviousTopic           ; no, try topic before it
  253.         jmp     short HelpBack_Exit     ; we succeeded, exit
  254. CurrentTopicBeep:
  255.         cCall   CowMoo                  ; tell user of error
  256. CurrentTopic:
  257.         mov     dx,si
  258.         mov     ax,di
  259.         cCall   DisplayHlpWndNc         ; display the topic
  260.         ;any error at this point must have been caused by OOM or Missing varhelp
  261.         or      al,al                   ; could we redisplay?
  262.         je      HelpBack_Exit           ; yes, we are done
  263.         cCall   GiveHelpOOM             ; display OOM message
  264. HelpBack_Exit:
  265.         DbAssertRel     curHelpFile,e,0,UI,<HelpBack: help file open>
  266. cEnd
  267. ;***
  268. ;CmdHelpPrev - Goto Previous Help Topic
  269. ;
  270. ;Purpose:
  271. ;       The user has requested that we goto the previous help topic. Beeps
  272. ;       if this is not possible or the help window is not open.
  273. ;
  274. ;Entry:
  275. ;       None.
  276. ;
  277. ;Exit:
  278. ;       None.
  279. ;
  280. ;Uses:
  281. ;       Per C Convention
  282. ;
  283. ;****
  284. cProc   CmdHelpPrev,<PUBLIC,NEAR>
  285. cBegin
  286.         cmp     fHelpVisible,0                  ; help window visible?
  287. DJMP    je      CmdHelpBeep                     ; no, beep and exit
  288. DbAssertTst     HelpFlags,ne,HLP_GOTBUF,UI,<CmdHelpPrev:Help window open but not HLP_GOTBUF>
  289.         and     HelpFlags,NOT (HLP_FAILFNF OR HLP_FAILOOM) ;  clear flags
  290.         mov     bx,oCurTopic                    ; get ptr to current topic
  291.         push    Word Ptr [bx].ContextNum+2      ; parameter to HelpNcPrev
  292.         push    Word Ptr [bx].ContextNum
  293.         cCall   HelpNcPrev                      ; get next NC
  294.         mov     cx,ax                           ; is it 0? (non available)
  295.         or      cx,dx
  296.         jne     CmdHelpDisplay                  ; no, try to display it
  297.         test    HelpFlags,HLP_FAILFNF OR HLP_FAILOOM ; already displayed msg
  298.         jz      CmdHelpBeep                     ; no, topic not found=>beep
  299. cEnd
  300. ;***
  301. ;CmdHelpNext - Goto Next Help Topic
  302. ;
  303. ;Purpose:
  304. ;       The user has requested that we goto the next help topic. Beeps
  305. ;       if this is not possible or the help window is not open.
  306. ;
  307. ;Entry:
  308. ;       None.
  309. ;
  310. ;Exit:
  311. ;       None.
  312. ;
  313. ;Uses:
  314. ;       Per C Convention
  315. ;
  316. ;****
  317. cProc   CmdHelpNext,<PUBLIC,NEAR>
  318. cBegin
  319.         cmp     fHelpVisible,0                  ; help window visible?
  320.         je      CmdHelpBeep                     ; no, beep and exit
  321. DbAssertTst     HelpFlags,ne,HLP_GOTBUF,UI,<CmdHelpNext:Help window open but not HLP_GOTBUF>
  322.         mov     bx,oCurTopic
  323.         mov     dx,Word Ptr [bx].ContextNum + 2 ; DX:AX = old context num
  324.         mov     ax,Word Ptr [bx].ContextNum
  325.         cCall   GetNextNc                       ; Set DX:AX
  326.         jz      CmdHelpError                    ; check for errors
  327. CmdHelpDisplay:                                 ; Called from CmdHelpPrev
  328.         cCall   DisplayHlpWndNc
  329.         or      al,al                           ; did we succeed?
  330.         je      CmdHelpNext_Exit                ; yes, return.
  331. CmdHelpError:
  332.         cmp     al,HELP_HANDLED                 ; Will someone else handle?
  333.         je      CmdHelpNext_Exit                ; yes, just exit
  334. DbAssertRelB    al,e,HELP_NF,UI,<CmdHelpNext:Illegal error>
  335. CmdHelpBeep:                                    ; NOTE: shared label
  336.         cCall   CowMoo                          ; beep the speaker
  337. CmdHelpNext_Exit:
  338. cEnd
  339. ;Routine added with [1]
  340. ;***
  341. ;NormalizeTopic - Convert a context number to a standard form
  342. ;
  343. ;Purpose:
  344. ;       The current implementation of the help engine allows a piece of text
  345. ;       to have multiple context strings, thus multiple context numbers.
  346. ;       While searching, we use the context number to specify when we have
  347. ;       wrapped around the file and reached the starting point.  Thus, we
  348. ;       have to Normalize the topic number so it is the same one that will
  349. ;       be returned from HelpNcPrev or HelpNcNext.
  350. ;
  351. ;Entry:
  352. ;       AX : topic ID
  353. ;
  354. ;Exit:
  355. ;       if (CX != 0)
  356. ;          DX:AX : topic number
  357. ;       else
  358. ;          error (will have been signaled)
  359. ;
  360. ;Uses:
  361. ;       Per C Convention
  362. ;****
  363. cProc   NormalizeTopic,<NEAR>
  364. cBegin
  365.         push    ax                      ; preserve Topic ID
  366.         mov     dx,iStaticHelpTopic     ; DX:SI = context number
  367.         ccall   HelpNcNext,<iStaticHelpTopic,AX> ; get previous one
  368.         pop     bx                      ; BX = topic ID
  369.         mov     cx,ax                   ; did we succeed?
  370.         or      cx,dx
  371.         jz      PrevNext                ; no, try to get one after the topic ID
  372.         cCall   HelpNcPrev,<DX,AX>      ; yes, do a Prev to get normalized NC
  373.         jmp     short CheckReturn       ; and return it
  374. PrevNext:
  375.         cCall   HelpNcPrev,<iStaticHelpTopic,bx> ; get NC before topic ID
  376.         mov     cx,ax                   ; did this succeed?
  377.         or      cx,dx
  378.         jz      NormalizeExit_Err       ; no, exit with error
  379.         cCall   HelpNcNext,<DX,AX>      ; get topic after that one
  380. CheckReturn:
  381.         mov     cx,ax                   ; set error condition
  382.         or      cx,dx
  383. NormalizeExit_Err:
  384. cEnd
  385. ;***
  386. ;ChngHelpCurTopic - Cleans up after a help search
  387. ;
  388. ;Purpose:
  389. ;       The three routine set (GetHelpCurTopic, GetHelpNextTopic,
  390. ;       ChngHelpCurTopic) are used for a search or scan of the help file.
  391. ;
  392. ;       This routine will take a topic ID that was used to terminate
  393. ;       the search and prepare things for continued operation of the
  394. ;       help system.  This routine should only be called if we are
  395. ;       exiting from a search in a topic other than the original
  396. ;       topic, and want to change that topic to be the new current topic.
  397. ;
  398. ;Entry:
  399. ;       CX = previous topic
  400. ;
  401. ;Exit:
  402. ;       None.
  403. ;****
  404. cProc   ChngHelpCurTopic,<NEAR>
  405. cBegin
  406. DbAssertTst     HelpFlags,e,HLP_VARHELP,UI,<ChngHelpCurTopic:Called when HLP_VARHELP>
  407.         mov     ax,cx                   ; Set DX:AX to NC of topic
  408.         mov     dx,iStaticHelpTopic
  409.         or      dx,dx                   ; check to see if it is valid
  410.         je      ChngHelp_Exit           ; no, just exit (we will close help wnd)
  411.         inc     cx                      ; Topic ID = UNDEFINED ?
  412.         je      ChngHelp_Exit           ; brif - identifier is invalid.
  413. DbAssertTst     HelpFlags,ne,HLP_GOTBUF,UI,<ChngHelpCurTopic:iStaticHelpTopic non 0 without HLP_GOTBUF>
  414.         cCall   RecordHelpHistory       ; record topic in help history list
  415. ChngHelp_Exit:
  416.         cCall   DrawDebugScr            ; make sure screen is redrawn so
  417.                                         ; we get proper help title.
  418. cEnd
  419. ;***
  420. ;GetHelpNextTopic - Prepares the next topic for looking
  421. ;
  422. ;Purpose:
  423. ;       The three routine set (GetHelpCurTopic, GetHelpNextTopic,
  424. ;       ChngHelpCurTopic) are used for a search or scan of the help file.
  425. ;
  426. ;       This routine will take a Topic ID and return the next physical
  427. ;       Topic ID.  If the presented Topic ID was the last one in a section,
  428. ;       this routine will wrap around to the begining of the section.
  429. ;
  430. ;
  431. ;Entry:
  432. ;       CX = previous topic
  433. ;
  434. ;Exit:
  435. ;       AX = new Topic Identifier if engine help
  436. ;            0                    if var help (will work as topic id)
  437. ;            UNDEFINED            if error
  438. ;****
  439. cProc   GetHelpNextTopic,<NEAR>,<DI>
  440. cBegin
  441.         DbChk   HoldBuf1                ; use BUF1 as a temporary buffer
  442.         test    HelpFlags,HLP_COMPRESS  ; help shutting down
  443. DJMP    jnz     NextTopic_Exit          ; yes, exit
  444.         mov     dx,iStaticHelpTopic     ; get static high word of NC
  445.         or      dx,dx                   ; is it 0 (help system shut down)
  446. DJMP    je      NextTopic_Fail          ; yes, return error
  447. DbAssertTst     HelpFlags,ne,HLP_GOTBUF,UI,<GetHelpNextTopic:iStaticHelpTopic non 0 without HLP_GOTBUF>
  448.         mov     ax,cx                   ; DX:AX = old topic number
  449.         cCall   GetNextNc               ; DX:AX = next context number
  450. DJMP    jnz     GotNextTopic            ; we were successful
  451.         cmp     al,HELP_HANDLED         ; error message already displayed?
  452. DJMP    je      NextTopic_Fail          ; yes, return error code
  453. DbAssertRelB    al,e,HELP_NF,UI,<GetHelpNextTopic:illegal error from GetNextNc>
  454.         ;Goto the first topic of this section of the file.  We are guarenteed
  455.         ;that the topic h.pg1 (MSG_FirstContextStr) exists at the begining of
  456.         ;each section of the help system.  Thus, we pick off the file name
  457.         ;part of any context string of the section and goto filename!h.pg1
  458.         mov     bx,oCurTopic                    ; get ptr to a legal buffer
  459.         mov     di,OFFSET DGROUP:B$Buf1         ; store results in B$Buf1
  460.         push    ds                              ; far ptr to buffer
  461.         push    di
  462.         push    Word Ptr [bx].ContextNum+2      ; context number
  463.         push    Word Ptr [bx].ContextNum
  464.         cCall   HelpSzContext                   ; get current filename
  465.         or      ax,ax                           ; was the call successful?
  466.         je      NextTopic_Fail                  ; no, exit with error
  467.         cCall   szSrchExcl,<DI>                 ; AX = pos of '!' or 0
  468. DbAssertRel     ax,ne,0,UI,<szComposeContext:Illegal string from HelpSzContext>
  469.         mov     bx,MSG_FirstContextStr          ; message to append
  470.         cCall   AppendBuf,<AX,BX>               ; stick it on
  471.         xchg    ax,bx
  472.         mov     Byte Ptr [bx],0                 ; and 0 terminate it.
  473.         ;Get the context number + context for this name
  474.         ;param for CalcNc pushed above
  475.         cCall   CalcNc,<DI>             ; convert to context number
  476.         jcxz    NextTopic_DbFail        ; brif we couldn't locate it
  477.         cCall   NormalizeTopic          ; normalize topic number
  478.         jcxz    NextTopic_Fail          ; brif it can't be normalized
  479. GotNextTopic:
  480.         mov     di,ax                   ; save value to be returned
  481.         cCall   BufferNc                ; BX = ptr to buffered context
  482.         or      al,al                   ; error in buffering?
  483.         jne     NextTopic_Fail          ; yes, return with error code
  484.         lea     ax,[bx].bdlHelpText     ; get ptr to BDL
  485.         cCall   SizeHelpContext,<ax>    ; AX = # lines in this topic
  486.                                         ; sets iFileSize
  487.         xchg    ax,di                   ; restore return value
  488.         jmp     short NextTopic_Exit    ; and return
  489. NextTopic_DbFail:
  490.         DbAssertRelB al,ne,HELP_NF,UI,<GethelpNextTopic:h.pg1 missing from file>
  491.         ;If we get a fatal error, we have to close the help window.  There
  492.         ;is no guarentee that we can redisplay the original topic, and to
  493.         ;display some random topic would be poor.  Thus, make sure the
  494.         ;bit to close the help window in DoDrawDebugScr is set.
  495. NextTopic_Fail:
  496.         or      HelpFlags,HLP_COMPRESS  ; close help window at earliest time
  497.         mov     ax,UNDEFINED            ; assume we will get an error
  498. NextTopic_Exit:
  499.         DbChk   FreeBuf1                ; release buffer
  500. cEnd
  501. ;***
  502. ;GetHelpCurTopic - Start search and returns the current topic id
  503. ;
  504. ;Purpose:
  505. ;       The three routine set (GetHelpCurTopic, GetHelpNextTopic,
  506. ;       ChngHelpCurTopic) are used for a search or scan of the help file.
  507. ;
  508. ;       This routine will prepare for a linear scan of the help file
  509. ;       and will return the Topic Id for the currently displayed help
  510. ;       topic.
  511. ;
  512. ;       A Topic ID is a word that references a help topic.  It is the
  513. ;       lower word of a NC, so it is valid only as long as we do not
  514. ;       shut down the help system.
  515. ;
  516. ;Entry:
  517. ;       None.
  518. ;
  519. ;Exit:
  520. ;       AX = cur Topic Identifier if engine help
  521. ;            0                    if var help (will work as topic id)
  522. ;            UNDEFINED            if error
  523. ;****
  524. cProc   GetHelpCurTopic,<NEAR>
  525. cBegin
  526.         test    HelpFlags,HLP_GOTBUF    ; are we initialized?
  527.         mov     ax,UNDEFINED            ; assume not
  528.         je      CurTopic_Exit           ; brif not - give error and ret.
  529. DbAssertRel     oCurTopic,ne,0,UI,<GetHelpCurTopic:oCurTopic invalid>
  530.         mov     bx,oCurTopic            ; get a pointer to the current topic
  531.         mov     ax,Word Ptr [bx].ContextNum ; get topic specific part of NC
  532.         mov     dx,Word Ptr [bx].ContextNum+2
  533.         mov     iStaticHelpTopic,dx     ; save static part of NC
  534.         cCall   NormalizeTopic          ; Normalize the topic number
  535.         inc     cx                      ; JCXNZ
  536.         loop    CurTopic_Exit           ; brif success
  537.         mov     ax,-1                   ; set failure flag
  538. CurTopic_Exit:
  539. cEnd
  540. ;Added with [4]
  541. ;***
  542. ;RestoreHelpTopic - Return help system to state before a search
  543. ;
  544. ;Purpose:
  545. ;       The search code needs the original help topic restored to the screen.
  546. ;       We get the topic from the help history list and redisplay it.
  547. ;
  548. ;       Note: we can not use DisplayHlpWndNc, as it will change the position
  549. ;       of the cursor and resize the window.
  550. ;
  551. ;
  552. ;Entry:
  553. ;       None.
  554. ;
  555. ;Exit:
  556. ;       None.
  557. ;
  558. ;****
  559. DbPub   RestoreHelpTopic
  560. cProc   RestoreHelpTopic,<NEAR>
  561. cBegin
  562.         test    HelpFlags,HLP_VARHELP   ; are we in variable help?
  563.         jnz     exit                    ; yes, exit. nothing to restore
  564.         cCall   RetrieveHelpHistory     ; get the last history item
  565. DbAssertRel     cx,ne,0,UI,<RestoreHelpTopic:History list empty>
  566.         push    ax                      ; save context number
  567.         push    dx
  568.         cCall   BufferNc                ; load context into memory, al=err code
  569.         pop     dx                      ; restore context number
  570.         pop     cx
  571.         or      al,al                   ; any errors?
  572.         jne     RestoreTopic_Fail       ; yes, handle them
  573.         push    bx                      ; save ptr to help context
  574.         xchg    ax,cx                   ; DX:AX = context number
  575.         cCall   RecordHelpHistory       ; save this in the history list
  576.         pop     bx                      ; return ptr to help context
  577.         lea     ax,[bx].bdlHelpText     ; Get ptr to BDL of this help topic
  578.         cCall   SizeHelpContext,<ax>    ; calculate size, set iFileSize
  579.         jmp     short exit              ; get out of here
  580. RestoreTopic_Fail:
  581.         DbAssertRelB    al,e,HELP_HANDLED,UI,<RestoreHelpTopic:Unable to regenerate initial topic>
  582.         or      HelpFlags,HLP_COMPRESS  ; no error should have happened, we
  583.                                         ; have no idea what state we are in,
  584.                                         ; so close help window
  585. exit:
  586. cEnd
  587. ;***
  588. ;GetHelpTitle - Returns the title for the currently displayed help item
  589. ;
  590. ;Purpose:
  591. ;       Calculates the title that should go on the help window and
  592. ;       returns it in bufStdMsg.
  593. ;
  594. ;Entry:
  595. ;       CX = max title length allowed
  596. ;
  597. ;Exit:
  598. ;       AX = number of characters in title
  599. ;       bufStdMsg = contains title.
  600. ;
  601. ;Uses:
  602. ;       Per Convention
  603. ;****
  604. DbPub   GetHelpTitle
  605. cProc   GetHelpTitle,<NEAR>,<SI>
  606. cBegin
  607.         mov     si,cx                   ; SI = cbMaxTitle
  608.         mov     ax,MSG_HelpTitleQH      ; first part of title ("MS-DOS Help: ")
  609.         test    cmdSwitches,CMD_SW_QHELP ; /QHELP viewer?
  610.         jnz     ght1                    ;   YES, got title
  611.         mov     ax,MSG_HelpTitle        ; Yes normal help window title
  612. ght1:
  613.         cCall   ListStdMsg,<AX>         ; put in bufStdMsg
  614.         mov     bl,HelpFlags                    ; get a copy of the flags
  615.         and     bl,HLP_GOTBUF or HLP_COMPRESS   ; mask out all but these
  616.         cmp     bl,HLP_GOTBUF                   ; brif NOT HLP_GOTBUF or
  617.         jne     GetHelpTitle_Exit               ;  HLP_COMPRESS
  618. ; HLP_INHELP will only be set if we are about to do something that can
  619. ; put up a dialog/message box.  If this routine is called with it set,
  620. ; then we are trying to redraw the screen after the box has been removed.
  621. ; This can be dangerious, as we may not be in a state where we can
  622. ; generate a help title.  So return with what we have.
  623.         test    HelpFlags,HLP_INHELP    ; are we called recursively?
  624.         jz      NotRecursiveGHT         ; no, try to get a title
  625.         cmp     fMessageBox,0           ; are we in a dialog box?
  626.         jnz     GetHelpTitle_Exit       ; yes, exit with what we have.
  627. NotRecursiveGHT:
  628. HelpTitleNotVarHelp:
  629.         mov     bx,oCurTopic
  630.         or      bx,bx                   ; current topic invalid?
  631.         je      GethelpTitle_Exit       ; yes, return with what we have
  632.         lea     ax,[bx].bdlHelpText     ; get ptr to the BDL
  633.         cCall   GetHelpTitleStr,<ax,si> ; AX = total length of title
  634. GetHelpTitle_Exit:
  635.         DbAssertRel ax,be,si,UI,<GetHelpTitle: title too big>
  636. cEnd
  637. ;***
  638. ;GetHelpLine - Get a line of help text
  639. ;
  640. ;Purpose:
  641. ;       This routine is called by the edit manager to display a line
  642. ;       of text on the screen.  This routine must take care of all
  643. ;       the cases associated with ressyncing the virtual line mechanism,
  644. ;       as well as detecting when a ressync would be needed.
  645. ;
  646. ;       Since this routine is called from COW, the line numbers are 0 relative.
  647. ;       The help system is 1 relative (because of the HelpEngine) so we
  648. ;       do the conversions on the fly.
  649. ;
  650. ;Entry:
  651. ;       CX = iLineNum - virtual line number of line to retrieve
  652. ;       DX = szBufPtr - pointer to buffer in which to store line
  653. ;       AX = cbMaxSize - maximum size of buffer
  654. ;
  655. ;Exit:
  656. ;       AX = # bytes in line
  657. ;
  658. ;****
  659. cProc   GetHelpLine,<NEAR>,<SI,DI>
  660. cBegin
  661.         mov     si,ax                           ; save entry params
  662.         mov     di,dx
  663.         mov     al,HelpFlags                    ; get a copy of the flags
  664.         and     al,HLP_GOTBUF or HLP_COMPRESS   ; mask out all but these
  665.         cmp     al,HLP_GOTBUF                   ; brif HLP_GOTBUF and
  666.         je      CheckHelpOwner                  ;  NOT HLP_COMPRESS
  667. GetLineError:
  668.         xor     ax,ax                           ; number of characters
  669. GetLine_NoAttr:
  670.         ; signal GetHelpLineAttr that it can't lookup attributes
  671.         mov     iCurRequestLine,UNDEFINED
  672.         jmp     short GetHelpLine_Exit          ; and return
  673. CheckHelpOwner:
  674.         inc     cx                              ; make 1 relative
  675. GotHelpLine:
  676.         mov     bx, oCurTopic                   ; get current topic pointer
  677.         or      bx,bx                           ; is it 0?
  678.         je      GetLineError                    ; yes, no current topic set
  679.         mov     iCurRequestLine,cx              ; set line # offset for attribs
  680.         lea     bx,[bx].bdlHelpText.BDL_Seg          ; BX = handle text seg
  681.         xor     ax,ax                                ; AX = text offset
  682.         cCall   HelpGetLine,<CX,SI,DS,DI,BX,AX>      ; put text into buff.
  683.         or      ax,ax                                ; did we get the line?
  684.         je      GetLineError                         ; no, signal error
  685.         ;AX = number of characters in buffer = return value
  686. GetHelpLine_Exit:
  687. cEnd
  688. ;***
  689. ;GetHelpLineAttr - return attributes for previously fetched line
  690. ;
  691. ;Purpose:
  692. ;       This routine will return the line attributes for the
  693. ;       line that was retrieved with the last call to GetHelpLine.
  694. ;
  695. ;       Note: No call that could change the state of the help system
  696. ;             should be called between GetHelpLine and this routine.
  697. ;
  698. ;Entry:
  699. ;       none.
  700. ;
  701. ;Exit:
  702. ;       AX = near ptr to string containing attributes
  703. ;
  704. ;Uses:
  705. ;       Per Convention
  706. ;
  707. ;****
  708. cProc   GetHelpLineAttr,<NEAR>
  709. cBegin
  710.         .errnz (-1) - (UNDEFINED)
  711.         mov     ax,iCurRequestLine              ; did GetHelpLine return bogus
  712.         inc     ax                              ; line (== -1 = UNDEFINED)?
  713.         jne     Get_Attr                        ; no, line is buffered
  714. DefaultAttrs:
  715.         mov     bx,OFFSET DGROUP:rgLineAttr     ; pointer to static buffer
  716.         push    bx                              ; save for return ptr
  717.         mov     ax,UNDEFINED
  718.         mov     [bx + LA_cb],ax
  719.         mov     [bx + LA_attr],isaSyntaxHelp
  720.         mov     [bx + (size LINEATTR) + LA_attr],ax
  721. DJMP    jmp     short GetAttr_End
  722. Get_Attr:
  723. ; we assume that nothing in the help system will change from the call to
  724. ; HelpGetLine.  Thus, we do not have to check that help is up and running,
  725. ; as HelpGetLine will zero iCurRequestLine if there are ANY problems.
  726. ; Also, CompressHelp will zero iCurRequestLine.
  727. DbAssertTst     HelpFlags,ne,HLP_GOTBUF,UI,<GetHelpLineAttr: HLP_GOTBUF not set>
  728. DbAssertRel     oCurTopic,ne,0,UI,<GetHelpLineAttr:Invalid oCurTopic>
  729.         mov     bx,oCurTopic
  730.         lea     bx,[bx].bdlHelpText.BDL_seg     ; get handle of topic seg
  731. ; a-emoryh Added more space for Dos6 online help index strings
  732.         mov     ax,CB_bufStdMsg + 6 + 16 + 70   ; maximum size of buffer
  733.         mov     cx,OFFSET DGROUP:bufStdMsg      ; buffer to store results in
  734.         push    cx                              ; save for mapping start
  735.         xor     dx,dx                           ; offset into topic segment
  736.         cCall   HelpGetLineAttr,<iCurRequestLine,AX,DS,CX,BX,DX>
  737.         pop     bx                              ; pointer to buffer
  738.         or      ax,ax                           ; did we succeed?
  739.         jz      DefaultAttrs                    ; no, use default attrs
  740.         ;Map attributes from HELP format to COW format
  741.         push    bx              ; save ptr to buffer for return
  742. AttrList:
  743.         mov     ax,[bx].LA_attr ; get first attribute
  744.         inc     ax              ; is it -1 (end of list)
  745.         je      GetAttr_End     ; yes, we are done
  746.         dec     ax              ; restore attribute
  747.         DbAssertTst ax,e,<NOT (A_BOLD OR A_UNDERLINE OR A_ITALICS)>,UI,<GetHelpLineAttr: Illegal attributes set>
  748.         mov     cx,isaBold      ; assume bold attribute
  749.         test    ax,A_BOLD       ; does it have any bold in it?
  750.         jne     GotAttr         ; yes, update and loop
  751.         mov     cx,isaUnderline ; assume underline attribute
  752.         test    ax,A_UNDERLINE  ; does it have any underline in it?
  753.         jne     GotAttr         ; yes, update and loop
  754.         mov     cx,isaItalic    ; assume italics attribute
  755.         test    ax,A_ITALICS    ; does it have any italics in it?
  756.         jne     GotAttr         ; yes, update and loop
  757.         mov     cx,isaSyntaxHelp; it must be default
  758. GotAttr:
  759.         mov     [bx].LA_attr,cx ; update attribute
  760.         add     bx,Size LINEATTR; point to next attribute/size pair
  761.         jmp     short AttrList  ; go modify this one.
  762. GetAttr_End:
  763.         pop     ax              ; retrieve pointer to begining of buffer
  764. cEnd
  765. ;***
  766. ;GetHelpFileSize - Returns the number of lines in the help file
  767. ;
  768. ;Purpose:
  769. ;       This routine is used to set the scroll bar, and to establish
  770. ;       the maximum line number in the file.  Since we currently use
  771. ;       a virtual file, we will return a virtual size.
  772. ;
  773. ;Entry:
  774. ;       None.
  775. ;
  776. ;Exit:
  777. ;       AX = size of file in lines
  778. ;
  779. ;Uses:
  780. ;       AX
  781. ;
  782. ;****
  783. DbPub   GetHelpFileSize
  784. cProc   GetHelpFileSize,<NEAR>
  785. cBegin
  786. ; HLP_INHELP will only be set if we are about to do something that can
  787. ; put up a dialog/message box.  If this routine is called with it set,
  788. ; then we are trying to redraw the screen after the box has been removed.
  789. ; This can be dangerious, as we may not be in a state where we can
  790. ; access a help topic.  Thus we will tell the edit manager that we
  791. ; have 0 lines, so it will not call us to redraw the screen.
  792.         mov     ax,iFileSize            ; get size of variable help
  793.         test    HelpFlags,HLP_INHELP    ; are we recursively entering help?
  794.         jz      ExitGHFS                ; no, return with what we got
  795.         cmp     fMessageBox,0           ; are we in a message box?
  796.         jz      ExitGHFS                ; no, return with what we got
  797.         cCall   DrawDebugScr            ; make sure we are redrawn later
  798.         xor     ax,ax                   ; return 0 lines
  799. ExitGHFS:
  800. cEnd
  801. ;***
  802. ;HelpWndProc - Window Proc for the help window
  803. ;
  804. ;Purpose:
  805. ;       This routine interprets all messages that are going to the help
  806. ;       window.  Those of interest is processes and returns a value.
  807. ;       Otherwize, it will pass the message on to EditFilterWndProc.
  808. ;
  809. ;       This routine implements the receiving end of the messaging system.
  810. ;       It must be able to be called recursively.
  811. ;
  812. ;Entry:
  813. ;       pwnd    - Ptr to window that is to receive the message
  814. ;       msg     - message
  815. ;       wParam  - Word parameter to message
  816. ;       lParamHi- Long word parameter to message, broken up for ease of use.
  817. ;       lParamLo-/
  818. ;
  819. ;Exit:
  820. ;       DX:AX - return value
  821. ;
  822. ;****
  823. labelW  MessageTable                    ; list of addresses for our messages
  824.         dw      UIOFFSET HelpBack
  825.         dw      UIOFFSET CmdHelpNext
  826.         dw      UIOFFSET DisplayHlpGeneric
  827.         dw      UIOFFSET GetHelpCurTopic
  828.         dw      UIOFFSET GetHelpNextTopic
  829.         dw      UIOFFSET ChngHelpCurTopic
  830.         dw      UIOFFSET RestoreHelpTopic
  831.         dw      UIOFFSET GetHelpTitle
  832.         dw      UIOFFSET GetHelpLine
  833.         dw      UIOFFSET GetHelpLineAttr
  834.         dw      UIOFFSET GetHelpFileSize
  835.         .errnz  (($ - MessageTable) / 2) - NUM_HELPMSG
  836. cProc   HelpWndProc,<PUBLIC,FAR>,<SI>
  837. parmW   pwnd
  838. parmW   msg
  839. parmW   wParam
  840. parmW   lParamHi
  841. parmW   lParamLo
  842. cBegin
  843.         inc     fHelpAlloc              ; set recursion flag
  844.         mov     cx,wParam               ; cache in a register for speed
  845.         mov     ax,msg                  ; cache in a register for speed
  846.         mov     bx,ax
  847.         sub     bx,WM_FIRSTHELPMSG      ; is it one of our special msgs?
  848.         cmp     bx,NUM_HELPMSG
  849.         jae     NotInTable              ; no, it is not in table
  850.         shl     bx,1                    ; make into a word index
  851.         mov     dx,lParamHi             ; Make lParam accessable
  852.         mov     ax,lParamLo
  853.         call    CS:MessageTable[bx]     ; and go do the code
  854.         jmp     WndProcExit_2           ; return with code from the call
  855. NotInTable:
  856.         cmp     ax,WM_LBUTTONDBLCLK
  857.         jne     CheckSETFOCUS
  858. DbAssertRel     pwnd,e,<OFFSET DGROUP:wndHelp>,UI,<HelpWndProc:mouse message not for Help window>
  859.         mov     bx,lParamLo
  860.         mov     al,bh                   ; al = screen relative row number
  861.         cbw                             ; ax = screen relative row number
  862.         add     ax,EfHelp.EF_pdCur_olnTop ; ax = file relative row number
  863.         xor     bh,bh                   ; bx = screen relative column number
  864.         add     bx,EfHelp.EF_pdCur_obleft ; bx = file relative column number
  865.         push    BX                      ; push first parameter
  866. SelectHotLinkTrue:
  867.         push    ax
  868. ; a-emoryh - Don't beep in QHelp mode when can't find hotlink
  869. ;            Do we really want to not beep, though?
  870.         mov     ax, 1                   ; assume do beep
  871.         test    cmdSwitches,CMD_SW_QHELP ; /QHELP viewer?
  872.         jz      hwpDoBeep
  873.         xor     ax, ax                  ; Qhelp mode, so clear beep flag
  874. hwpDoBeep:
  875.         push    ax
  876. ;; Old line
  877. ;        push    sp
  878.         cCall   SelectHotLink           ; select hot link, allow BEEP
  879.         jmp     WndProcExit
  880. CheckSETFOCUS:
  881.         cmp     ax,WM_SETFOCUS
  882.         jne     CheckSETBOOKMARK
  883.         PUSHI   ax,<OFFSET DGROUP:wndHelp> ; borrow the SETFOCUS call to
  884.         cCall   DoStatusMsg             ; update the status line message
  885.         jmp     Short DefaultCase       ; Pass call onto the edit mgr.
  886. CheckSETBOOKMARK:
  887.         cmp     ax,WM_SETBOOKMARK
  888.         jne     CheckGOTOBOOKMARK
  889.         sub     cx,'0'                  ; CX = wParam - '0'
  890.         cCall   SetBookMark,<CX>
  891.         jmp     short WndProcExit
  892. CheckGOTOBOOKMARK:
  893.         cmp     ax,WM_GOTOBOOKMARK
  894.         jne     CheckCHAR
  895.         sub     cx,'0'                  ; CX = wParam - '0'
  896.         cCall   GotoBookMark,<CX>
  897.         jmp     short WndProcExit
  898. CheckCHAR:
  899.         cmp     ax,WM_CHAR
  900.         jne     DefaultCase
  901.         cmp     cx,09h                  ; is the character a TAB
  902.         jne     NotTab                  ; no, go check for ENTER
  903.         xor     ax,ax                   ; assume not shifted
  904.         test    lParamHi,KK_SHIFT       ; is a shift key pressed?
  905.         jz      GotoHotLink             ; no, use a value of 0
  906.         dec     ax                      ; use -1
  907. GotoHotLink:
  908.         cCall   NextHotLink,<AX>
  909.         jmp     short WndProcExit
  910. NotTab:
  911.         cmp     cx,0dh                  ; is the character an ENTER?
  912.         jne     NotEnter                ; no, go test for another char
  913.         cCall   GetEditColumn           ; AX = file relative column number
  914.         push    ax
  915.         cCall   GetEditLine             ; AX = file relative line number
  916.         jmp     SelectHotLinkTrue       ; select hot link (AX = line)
  917. NotEnter:                               ; check for legal characters
  918.         cmp     cx,7fh                  ; is it a backspace?
  919.         je      DefaultCase             ; yes,  let EditMgr have it
  920.         or      ch,ch                   ; is it a virtual key
  921.         jne     DefaultCase             ; yes, EditMgr will handle it
  922.         cmp     cx,' '                  ; is it a control character
  923.         jb      DefaultCase             ; yes, let EditMgr have it
  924.         cCall   GetEditMgrState         ; Ctrl+Q or Ctrl+K active?
  925.         or      ax,ax                   ; (non-zero if so)
  926.         jnz     DefaultCase             ; yes, EditMgr will handle this
  927.         cCall   toupper,<wParam>        ; convert parameter to uppercase
  928.         cmp     ax,wParam               ; was it already upper?
  929.         jne     GotoHotLink             ; no, goto hotlink
  930.         neg     ax                      ; yes, tell hotlink to look backwards
  931.         jmp     GotoHotLink             ; goto hotlink.
  932. DefaultCase:
  933.         cCall   EditFilterWndProc,<pwnd,msg,wParam,lParamHi,lParamLo>
  934.         jmp     short WndProcExit_2
  935. WndProcExit:
  936.         xor     ax,ax                   ; return 0L
  937.         cwd
  938. WndProcExit_2:
  939.         dec     fHelpAlloc              ; release allocation lock
  940.         cCall   CloseCurHelpFile        ; close the current help file
  941. cEnd
  942. sEnd    UI
  943.         end