~nme/nme/1.1

« back to all changes in this revision

Viewing changes to Src/NMEMFC.h

  • Committer: michael.owens at linterra
  • Date: 2008-11-19 17:49:21 UTC
  • Revision ID: michael.owens@linterra.org-20081119174921-5rh22x5qdh6ltf4o
Initial submission.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *      @file NMEMFC.h
 
3
 *      @brief Support for MFC (Windows) .
 
4
 *      @author Yves Piguet. Copyright 2007-2008, Yves Piguet
 
5
 *
 
6
 *      @section Links Links
 
7
 *
 
8
 *      Here is how to support links in a CRichEditView (assuming the subclass name
 
9
 *      is S and the control id is ID):
 
10
 *      - Enable links in method S::OnCreate, e.g. with
 
11
 *      @code
 
12
 *      GetRichEditCtrl().SetEventMask(GetRichEditCtrl().GetEventMask() | ENM_LINK);
 
13
 *      @endcode
 
14
 *      - Add the following protected method prototype in the header file:
 
15
 *      @code
 
16
 *      afx_msg void OnEnLink(NMHDR* pNMHDR, LRESULT* pResult);
 
17
 *      @endcode
 
18
 *      - Add the following method definition to CRichEditView's subclass (you can write
 
19
 *      your own NMEMFCLinkFun function if you want to process links in a special way):
 
20
 *      @code
 
21
 *      void S::OnEnLink(NMHDR* pNMHDR, LRESULT* pResult)
 
22
 *      {
 
23
 *        NMEMFCEnLink(pNMHDR, pResult, NMEMFCLinkFunURL);
 
24
 *      }
 
25
 *      @endcode
 
26
 *      - Add the following line between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP:
 
27
 *      @code
 
28
 *      ON_NOTIFY(EN_LINK, ID, OnEnLink)
 
29
 *      @endcode
 
30
 *      - call NMEMFCSetRichText with argument link set to TRUE
 
31
 *
 
32
 *      You should replace ON_NOTIFY with ON_NOTIFY_RANGE and define
 
33
 *      S::OnEnLinkRange(UINT id, NMHDR* pNMHDR, LRESULT* pResult) if you have to
 
34
 *      handle multiple CRichEditView controls with one method.
 
35
 */
 
36
 
 
37
#ifndef __NMEMFC__
 
38
#define __NMEMFC__
 
39
 
 
40
#include "NME.h"
 
41
#include "NMEStyle.h"
 
42
 
 
43
#include <afxrich.h>
 
44
 
 
45
/** Callback to handle link clicks.
 
46
        @param[in] link raw link, as in NME source text, without leading and
 
47
        trailing spaces (null-terminated string)
 
48
        @param[in,out] data data value specific to the callback
 
49
*/
 
50
typedef void (*NMEMFCLinkFun)(NMEConstText link, void *data);
 
51
 
 
52
/** Replace selection in a CRichEditCtrl with NME text converted
 
53
        to styled text.
 
54
        @param[in,out] c MFC rich text control
 
55
        @param[in] input text with NME markup
 
56
        @param[in] inputLength length of input, or negative if input is
 
57
        null-terminated
 
58
        @param[in] replaceSel if TRUE, replace selection, else replace whole text
 
59
        @param[in] plainTextCharFormat character format of plain text (if NULL, use
 
60
        default character format of c)
 
61
        @param[in] links TRUE to enable links, else FALSE
 
62
*/
 
63
void NMEMFCSetRichText(CRichEditCtrl &c,
 
64
                char const *input, int inputLength = -1,
 
65
                bool replaceSel = FALSE,
 
66
                CHARFORMAT const *plainTextCharFormat = NULL,
 
67
                bool links = FALSE);
 
68
 
 
69
/** Replace selection in a CRichEditCtrl with NME text converted
 
70
        to styled text.
 
71
        @param[in,out] c MFC rich text control
 
72
        @param[in] input text as UCS-16 with NME markup
 
73
        @param[in] inputLength length of input, or negative if input is
 
74
        null-terminated
 
75
        @param[in] replaceSel if TRUE, replace selection, else replace whole text
 
76
        @param[in] plainTextCharFormat character format of plain text (if NULL, use
 
77
        default character format of c)
 
78
        @param[in] links TRUE to enable links, else FALSE
 
79
*/
 
80
void NMEMFCSetRichText(CRichEditCtrl &c,
 
81
                WCHAR const *input, int inputLength = -1,
 
82
                bool replaceSel = FALSE,
 
83
                CHARFORMAT const *plainTextCharFormat = NULL,
 
84
                bool links = FALSE);
 
85
 
 
86
/**     Handle links (should be called when an EN_LINK notification is received).
 
87
        @param[in] pNMHDR notification message
 
88
        @param[out] pResult result code
 
89
        @param[in] linkFun callback which handles link clicks
 
90
        @param[in] linkFunData value passed to linkFun
 
91
*/
 
92
void NMEMFCEnLink(NMHDR const *pNMHDR, LRESULT* pResult,
 
93
                NMEMFCLinkFun linkFun, void *linkFunData = NULL);
 
94
 
 
95
/**     NMEMFCLinkFun callback to let Windows process URL (can be used as is
 
96
        or called from a user-written callback which recognizes other kinds of
 
97
        links).
 
98
        @param[in] link raw URL, as in NME source text, without leading and
 
99
        trailing spaces (null-terminated string)
 
100
        @param[in,out] data not used
 
101
*/
 
102
void NMEMFCLinkFunURL(NMEConstText link, void *data = NULL);
 
103
 
 
104
#endif