1 | #define INCL_WIN |
---|
2 | #include <os2.h> |
---|
3 | |
---|
4 | #include <process.h> |
---|
5 | |
---|
6 | #include <ludoc.xh> |
---|
7 | |
---|
8 | #include "luutils.h" |
---|
9 | #include "fontsInfoDlg.h" |
---|
10 | #include "Lucide_res.h" |
---|
11 | #include "messages.h" |
---|
12 | |
---|
13 | |
---|
14 | FontsInfoDlg::FontsInfoDlg( HWND hWndFrame, LuDocument *_doc ) |
---|
15 | { |
---|
16 | hFrame = hWndFrame; |
---|
17 | doc = _doc; |
---|
18 | hDialog = NULLHANDLE; |
---|
19 | hContainer = NULLHANDLE; |
---|
20 | name = newstrdupL( FONTINFO_NAME ); |
---|
21 | type = newstrdupL( FONTINFO_TYPE ); |
---|
22 | embed = newstrdupL( FONTINFO_EMBEDDED ); |
---|
23 | } |
---|
24 | |
---|
25 | FontsInfoDlg::~FontsInfoDlg() |
---|
26 | { |
---|
27 | delete name; |
---|
28 | delete type; |
---|
29 | delete embed; |
---|
30 | } |
---|
31 | |
---|
32 | void FontsInfoDlg::doDialog() |
---|
33 | { |
---|
34 | WinDlgBox( HWND_DESKTOP, hFrame, fontsInfoDlgProc, |
---|
35 | NULLHANDLE, IDD_FONTINFO, this ); |
---|
36 | delete this; |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | struct ListRec |
---|
41 | { |
---|
42 | MINIRECORDCORE miniRecordCore; |
---|
43 | PSZ type; |
---|
44 | PSZ embed; |
---|
45 | }; |
---|
46 | |
---|
47 | |
---|
48 | void FontsInfoDlg::loadList() |
---|
49 | { |
---|
50 | Environment *ev = somGetGlobalEnvironment(); |
---|
51 | LuDocument_LuFontInfoSequence *fonts = doc->getFontInfo( ev ); |
---|
52 | |
---|
53 | if ( fonts != NULL ) |
---|
54 | { |
---|
55 | for ( int i = 0; i < fonts->_length; i++ ) |
---|
56 | { |
---|
57 | ListRec *r = (ListRec *)WinSendMsg( hContainer, CM_ALLOCRECORD, |
---|
58 | MPFROMLONG( ( sizeof( ListRec ) - sizeof( MINIRECORDCORE ) ) ), |
---|
59 | MPFROMSHORT( 1 ) ); |
---|
60 | |
---|
61 | r->miniRecordCore.cb = sizeof( MINIRECORDCORE ); |
---|
62 | r->miniRecordCore.flRecordAttr = 0; |
---|
63 | r->miniRecordCore.ptlIcon.x = 0; |
---|
64 | r->miniRecordCore.ptlIcon.y = 0; |
---|
65 | r->miniRecordCore.pszIcon = newstrdup( fonts->_buffer[i].name ); |
---|
66 | r->miniRecordCore.hptrIcon = NULLHANDLE; |
---|
67 | r->type = newstrdup( fonts->_buffer[i].type ); |
---|
68 | r->embed = newstrdup( fonts->_buffer[i].embedded ); |
---|
69 | |
---|
70 | RECORDINSERT ri; |
---|
71 | ri.cb = sizeof( RECORDINSERT ); |
---|
72 | ri.pRecordParent= NULL; |
---|
73 | ri.pRecordOrder = (PRECORDCORE)CMA_END; |
---|
74 | ri.zOrder = (USHORT)CMA_TOP; |
---|
75 | ri.cRecordsInsert = 1; |
---|
76 | ri.fInvalidateRecord = TRUE; |
---|
77 | WinSendMsg( hContainer, CM_INSERTRECORD, MPFROMP( r ), MPFROMP( &ri ) ); |
---|
78 | } |
---|
79 | |
---|
80 | LuDocument::freeFontInfo( ev, fonts ); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | void FontsInfoDlg::loadthread( void *p ) |
---|
85 | { |
---|
86 | FontsInfoDlg *_this = (FontsInfoDlg *)p; |
---|
87 | HAB thab = WinInitialize( 0 ); |
---|
88 | HMQ thmq = WinCreateMsgQueue( thab, 0 ); |
---|
89 | |
---|
90 | _this->loadList(); |
---|
91 | |
---|
92 | WinSetDlgItemText( _this->hDialog, IDC_ENUMLABEL, "" ); |
---|
93 | WinEnableControl( _this->hDialog, DID_OK, TRUE ); |
---|
94 | WinInvalidateRect( _this->hDialog, NULL, TRUE ); |
---|
95 | |
---|
96 | WinDestroyMsgQueue( thmq ); |
---|
97 | WinTerminate( thab ); |
---|
98 | _endthread(); |
---|
99 | } |
---|
100 | |
---|
101 | MRESULT EXPENTRY FontsInfoDlg::fontsInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) |
---|
102 | { |
---|
103 | // This is a static method, so we don't know which instantiation we're |
---|
104 | // dealing with. But we can get a pseudo-this from the parameter to |
---|
105 | // WM_INITDLG, which we therafter store with the window and retrieve |
---|
106 | // as follows: |
---|
107 | FontsInfoDlg *_this = (FontsInfoDlg *)WinQueryWindowULong( hwnd, QWL_USER ); |
---|
108 | |
---|
109 | switch (msg) |
---|
110 | { |
---|
111 | |
---|
112 | // Dialog has just been created |
---|
113 | case WM_INITDLG: |
---|
114 | { |
---|
115 | // Save the mp2 into our user data so that subsequent calls have |
---|
116 | // access to the parent C++ object |
---|
117 | WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 ); |
---|
118 | _this = (FontsInfoDlg *)mp2; |
---|
119 | _this->hDialog = hwnd; |
---|
120 | _this->hContainer = WinWindowFromID( hwnd, IDC_FONTSLIST ); |
---|
121 | localizeDialog( hwnd ); |
---|
122 | centerWindow( _this->hFrame, hwnd ); |
---|
123 | |
---|
124 | // init container |
---|
125 | CNRINFO ci; |
---|
126 | ci.cb = sizeof( CNRINFO ); |
---|
127 | WinSendMsg( _this->hContainer, CM_QUERYCNRINFO, MPFROMP( &ci ), MPFROMSHORT( ci.cb ) ); |
---|
128 | ci.flWindowAttr &= ~( CV_NAME | CV_FLOW | CV_TEXT | CV_ICON ); |
---|
129 | ci.flWindowAttr |= ( CV_DETAIL | CV_MINI | CA_DETAILSVIEWTITLES ); |
---|
130 | WinSendMsg( _this->hContainer, CM_SETCNRINFO, MPFROMP( &ci ), MPFROMLONG( CMA_FLWINDOWATTR ) ); |
---|
131 | |
---|
132 | PFIELDINFO pFieldInfo = (PFIELDINFO)WinSendMsg( _this->hContainer, CM_ALLOCDETAILFIELDINFO, |
---|
133 | MPFROMSHORT( 3 ), MPVOID ); |
---|
134 | PFIELDINFO pFldInfo = pFieldInfo; |
---|
135 | pFldInfo->cb = sizeof( FIELDINFO ); |
---|
136 | pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR; |
---|
137 | pFldInfo->flTitle = CFA_CENTER; |
---|
138 | pFldInfo->pTitleData = (PVOID)_this->name; |
---|
139 | pFldInfo->offStruct = FIELDOFFSET( ListRec, miniRecordCore.pszIcon ); |
---|
140 | pFldInfo = pFldInfo->pNextFieldInfo; |
---|
141 | pFldInfo->cb = sizeof( FIELDINFO ); |
---|
142 | pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR; |
---|
143 | pFldInfo->flTitle = CFA_CENTER; |
---|
144 | pFldInfo->pTitleData = (PVOID)_this->type; |
---|
145 | pFldInfo->offStruct = FIELDOFFSET( ListRec, type ); |
---|
146 | pFldInfo = pFldInfo->pNextFieldInfo; |
---|
147 | pFldInfo->cb = sizeof( FIELDINFO ); |
---|
148 | pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR; |
---|
149 | pFldInfo->flTitle = CFA_CENTER; |
---|
150 | pFldInfo->pTitleData = (PVOID)_this->embed; |
---|
151 | pFldInfo->offStruct = FIELDOFFSET( ListRec, embed ); |
---|
152 | |
---|
153 | FIELDINFOINSERT fieldInfoInsert; |
---|
154 | fieldInfoInsert.cb = sizeof( FIELDINFOINSERT ); |
---|
155 | fieldInfoInsert.pFieldInfoOrder = (PFIELDINFO)CMA_FIRST; |
---|
156 | fieldInfoInsert.cFieldInfoInsert = 3; |
---|
157 | fieldInfoInsert.fInvalidateFieldInfo = TRUE; |
---|
158 | WinSendMsg( _this->hContainer, CM_INSERTDETAILFIELDINFO, |
---|
159 | MPFROMP( pFieldInfo ), MPFROMP( &fieldInfoInsert ) ); |
---|
160 | |
---|
161 | _beginthread( loadthread, NULL, 32768, _this ); |
---|
162 | |
---|
163 | return (MRESULT)FALSE; |
---|
164 | } |
---|
165 | |
---|
166 | case WM_DESTROY: |
---|
167 | { |
---|
168 | ListRec *pRecords = (ListRec *)WinSendMsg( _this->hContainer, CM_QUERYRECORD, |
---|
169 | MPFROMP( NULL ), MPFROM2SHORT( CMA_FIRST, CMA_ITEMORDER ) ); |
---|
170 | ListRec *pr = pRecords; |
---|
171 | |
---|
172 | while ( pr != NULL ) |
---|
173 | { |
---|
174 | delete pr->miniRecordCore.pszIcon; |
---|
175 | delete pr->type; |
---|
176 | delete pr->embed; |
---|
177 | pr = (ListRec *)WinSendMsg( _this->hContainer, CM_QUERYRECORD, |
---|
178 | MPFROMP( pr ), MPFROM2SHORT( CMA_NEXT, CMA_ITEMORDER ) ); |
---|
179 | } |
---|
180 | WinSendMsg( _this->hContainer, CM_REMOVERECORD, |
---|
181 | MPFROMP( NULL ), MPFROM2SHORT( 0, CMA_FREE ) ); |
---|
182 | } |
---|
183 | break; |
---|
184 | |
---|
185 | } |
---|
186 | return WinDefDlgProc( hwnd, msg, mp1, mp2 ); |
---|
187 | } |
---|
188 | |
---|