1 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
2 | * Version: CDDL 1.0/LGPL 2.1 |
---|
3 | * |
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND |
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use |
---|
6 | * this file except in compliance with the License. You may obtain a copy of |
---|
7 | * the License at http://www.sun.com/cddl/ |
---|
8 | * |
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis, |
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
---|
11 | * for the specific language governing rights and limitations under the |
---|
12 | * License. |
---|
13 | * |
---|
14 | * The Initial Developer of the Original Code is |
---|
15 | * Eugene Romanenko, netlabs.org. |
---|
16 | * Portions created by the Initial Developer are Copyright (C) 2006 |
---|
17 | * the Initial Developer. All Rights Reserved. |
---|
18 | * |
---|
19 | * Contributor(s): |
---|
20 | * |
---|
21 | * Alternatively, the contents of this file may be used under the terms of |
---|
22 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
23 | * in which case the provisions of the LGPL are applicable instead of those |
---|
24 | * above. If you wish to allow use of your version of this file only under the |
---|
25 | * terms of the LGPL, and not to allow others to use your version of this file |
---|
26 | * under the terms of the CDDL, indicate your decision by deleting the |
---|
27 | * provisions above and replace them with the notice and other provisions |
---|
28 | * required by the LGPL. If you do not delete the provisions above, a recipient |
---|
29 | * may use your version of this file under the terms of any one of the CDDL |
---|
30 | * or the LGPL. |
---|
31 | * |
---|
32 | * ***** END LICENSE BLOCK ***** */ |
---|
33 | |
---|
34 | |
---|
35 | #define INCL_WIN |
---|
36 | #include <os2.h> |
---|
37 | |
---|
38 | #include <process.h> |
---|
39 | |
---|
40 | #include <ludoc.xh> |
---|
41 | |
---|
42 | #include "globals.h" |
---|
43 | #include "luutils.h" |
---|
44 | #include "fontsInfoDlg.h" |
---|
45 | #include "Lucide_res.h" |
---|
46 | #include "messages.h" |
---|
47 | |
---|
48 | |
---|
49 | FontsInfoDlg::FontsInfoDlg( HWND hWndFrame, LuDocument *_doc ) |
---|
50 | { |
---|
51 | hFrame = hWndFrame; |
---|
52 | doc = _doc; |
---|
53 | hDialog = NULLHANDLE; |
---|
54 | hContainer = NULLHANDLE; |
---|
55 | name = newstrdupL( FONTINFO_NAME ); |
---|
56 | type = newstrdupL( FONTINFO_TYPE ); |
---|
57 | embed = newstrdupL( FONTINFO_EMBEDDED ); |
---|
58 | emb_notembedded = newstrdupL( FONTINFO_EMBED_NOT_EMBEDDED ); |
---|
59 | emb_embedded = newstrdupL( FONTINFO_EMBED_EMBEDDED ); |
---|
60 | emb_embeddedsubset = newstrdupL( FONTINFO_EMBED_EMBEDDED_SUBSET ); |
---|
61 | } |
---|
62 | |
---|
63 | FontsInfoDlg::~FontsInfoDlg() |
---|
64 | { |
---|
65 | delete name; |
---|
66 | delete type; |
---|
67 | delete embed; |
---|
68 | delete emb_notembedded; |
---|
69 | delete emb_embedded; |
---|
70 | delete emb_embeddedsubset; |
---|
71 | } |
---|
72 | |
---|
73 | void FontsInfoDlg::doDialog() |
---|
74 | { |
---|
75 | WinDlgBox( HWND_DESKTOP, hFrame, fontsInfoDlgProc, |
---|
76 | _hmod, IDD_FONTINFO, this ); |
---|
77 | delete this; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | struct ListRec |
---|
82 | { |
---|
83 | MINIRECORDCORE miniRecordCore; |
---|
84 | PSZ type; |
---|
85 | PSZ embed; |
---|
86 | }; |
---|
87 | |
---|
88 | |
---|
89 | void FontsInfoDlg::loadList() |
---|
90 | { |
---|
91 | LuDocument_LuFontInfoSequence *fonts = doc->getFontInfo( ev ); |
---|
92 | |
---|
93 | if ( fonts != NULL ) |
---|
94 | { |
---|
95 | for ( int i = 0; i < fonts->_length; i++ ) |
---|
96 | { |
---|
97 | ListRec *r = (ListRec *)WinSendMsg( hContainer, CM_ALLOCRECORD, |
---|
98 | MPFROMLONG( ( sizeof( ListRec ) - sizeof( MINIRECORDCORE ) ) ), |
---|
99 | MPFROMSHORT( 1 ) ); |
---|
100 | |
---|
101 | r->miniRecordCore.cb = sizeof( MINIRECORDCORE ); |
---|
102 | r->miniRecordCore.flRecordAttr = 0; |
---|
103 | r->miniRecordCore.ptlIcon.x = 0; |
---|
104 | r->miniRecordCore.ptlIcon.y = 0; |
---|
105 | r->miniRecordCore.pszIcon = newstrdup( fonts->_buffer[i].name ); |
---|
106 | r->miniRecordCore.hptrIcon = NULLHANDLE; |
---|
107 | r->type = newstrdup( fonts->_buffer[i].type ); |
---|
108 | r->embed = NULL; |
---|
109 | switch ( fonts->_buffer[i].embedded ) |
---|
110 | { |
---|
111 | case LU_FONTEMBED_NOT_EMBEDDED: |
---|
112 | r->embed = newstrdup( emb_notembedded ); |
---|
113 | break; |
---|
114 | case LU_FONTEMBED_EMBEDDED: |
---|
115 | r->embed = newstrdup( emb_embedded ); |
---|
116 | break; |
---|
117 | case LU_FONTEMBED_EMBEDDED_SUBSET: |
---|
118 | r->embed = newstrdup( emb_embeddedsubset ); |
---|
119 | break; |
---|
120 | } |
---|
121 | |
---|
122 | RECORDINSERT ri; |
---|
123 | ri.cb = sizeof( RECORDINSERT ); |
---|
124 | ri.pRecordParent= NULL; |
---|
125 | ri.pRecordOrder = (PRECORDCORE)CMA_END; |
---|
126 | ri.zOrder = (USHORT)CMA_TOP; |
---|
127 | ri.cRecordsInsert = 1; |
---|
128 | ri.fInvalidateRecord = TRUE; |
---|
129 | WinSendMsg( hContainer, CM_INSERTRECORD, MPFROMP( r ), MPFROMP( &ri ) ); |
---|
130 | } |
---|
131 | |
---|
132 | LuDocument::freeFontInfo( ev, fonts ); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | void FontsInfoDlg::loadthread( void *p ) |
---|
137 | { |
---|
138 | FontsInfoDlg *_this = (FontsInfoDlg *)p; |
---|
139 | HAB thab = WinInitialize( 0 ); |
---|
140 | HMQ thmq = WinCreateMsgQueue( thab, 0 ); |
---|
141 | |
---|
142 | _this->loadList(); |
---|
143 | |
---|
144 | WinSetDlgItemText( _this->hDialog, IDC_ENUMLABEL, "" ); |
---|
145 | WinEnableControl( _this->hDialog, DID_OK, TRUE ); |
---|
146 | WinInvalidateRect( _this->hDialog, NULL, TRUE ); |
---|
147 | |
---|
148 | WinDestroyMsgQueue( thmq ); |
---|
149 | WinTerminate( thab ); |
---|
150 | _endthread(); |
---|
151 | } |
---|
152 | |
---|
153 | MRESULT EXPENTRY FontsInfoDlg::fontsInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) |
---|
154 | { |
---|
155 | // This is a static method, so we don't know which instantiation we're |
---|
156 | // dealing with. But we can get a pseudo-this from the parameter to |
---|
157 | // WM_INITDLG, which we therafter store with the window and retrieve |
---|
158 | // as follows: |
---|
159 | FontsInfoDlg *_this = (FontsInfoDlg *)WinQueryWindowULong( hwnd, QWL_USER ); |
---|
160 | |
---|
161 | switch (msg) |
---|
162 | { |
---|
163 | |
---|
164 | // Dialog has just been created |
---|
165 | case WM_INITDLG: |
---|
166 | { |
---|
167 | // Save the mp2 into our user data so that subsequent calls have |
---|
168 | // access to the parent C++ object |
---|
169 | WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 ); |
---|
170 | _this = (FontsInfoDlg *)mp2; |
---|
171 | _this->hDialog = hwnd; |
---|
172 | _this->hContainer = WinWindowFromID( hwnd, IDC_FONTSLIST ); |
---|
173 | localizeDialog( hwnd ); |
---|
174 | centerWindow( _this->hFrame, hwnd ); |
---|
175 | |
---|
176 | // init container |
---|
177 | CNRINFO ci; |
---|
178 | ci.cb = sizeof( CNRINFO ); |
---|
179 | WinSendMsg( _this->hContainer, CM_QUERYCNRINFO, MPFROMP( &ci ), MPFROMSHORT( ci.cb ) ); |
---|
180 | ci.flWindowAttr &= ~( CV_NAME | CV_FLOW | CV_TEXT | CV_ICON ); |
---|
181 | ci.flWindowAttr |= ( CV_DETAIL | CV_MINI | CA_DETAILSVIEWTITLES ); |
---|
182 | WinSendMsg( _this->hContainer, CM_SETCNRINFO, MPFROMP( &ci ), MPFROMLONG( CMA_FLWINDOWATTR ) ); |
---|
183 | |
---|
184 | PFIELDINFO pFieldInfo = (PFIELDINFO)WinSendMsg( _this->hContainer, CM_ALLOCDETAILFIELDINFO, |
---|
185 | MPFROMSHORT( 3 ), MPVOID ); |
---|
186 | PFIELDINFO pFldInfo = pFieldInfo; |
---|
187 | pFldInfo->cb = sizeof( FIELDINFO ); |
---|
188 | pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR; |
---|
189 | pFldInfo->flTitle = CFA_CENTER; |
---|
190 | pFldInfo->pTitleData = (PVOID)_this->name; |
---|
191 | pFldInfo->offStruct = FIELDOFFSET( ListRec, miniRecordCore.pszIcon ); |
---|
192 | pFldInfo = pFldInfo->pNextFieldInfo; |
---|
193 | pFldInfo->cb = sizeof( FIELDINFO ); |
---|
194 | pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR; |
---|
195 | pFldInfo->flTitle = CFA_CENTER; |
---|
196 | pFldInfo->pTitleData = (PVOID)_this->type; |
---|
197 | pFldInfo->offStruct = FIELDOFFSET( ListRec, type ); |
---|
198 | pFldInfo = pFldInfo->pNextFieldInfo; |
---|
199 | pFldInfo->cb = sizeof( FIELDINFO ); |
---|
200 | pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR; |
---|
201 | pFldInfo->flTitle = CFA_CENTER; |
---|
202 | pFldInfo->pTitleData = (PVOID)_this->embed; |
---|
203 | pFldInfo->offStruct = FIELDOFFSET( ListRec, embed ); |
---|
204 | |
---|
205 | FIELDINFOINSERT fieldInfoInsert; |
---|
206 | fieldInfoInsert.cb = sizeof( FIELDINFOINSERT ); |
---|
207 | fieldInfoInsert.pFieldInfoOrder = (PFIELDINFO)CMA_FIRST; |
---|
208 | fieldInfoInsert.cFieldInfoInsert = 3; |
---|
209 | fieldInfoInsert.fInvalidateFieldInfo = TRUE; |
---|
210 | WinSendMsg( _this->hContainer, CM_INSERTDETAILFIELDINFO, |
---|
211 | MPFROMP( pFieldInfo ), MPFROMP( &fieldInfoInsert ) ); |
---|
212 | |
---|
213 | _beginthread( loadthread, NULL, 32768, _this ); |
---|
214 | |
---|
215 | return (MRESULT)FALSE; |
---|
216 | } |
---|
217 | |
---|
218 | case WM_DESTROY: |
---|
219 | { |
---|
220 | ListRec *pRecords = (ListRec *)WinSendMsg( _this->hContainer, CM_QUERYRECORD, |
---|
221 | MPFROMP( NULL ), MPFROM2SHORT( CMA_FIRST, CMA_ITEMORDER ) ); |
---|
222 | ListRec *pr = pRecords; |
---|
223 | |
---|
224 | while ( pr != NULL ) |
---|
225 | { |
---|
226 | delete pr->miniRecordCore.pszIcon; |
---|
227 | delete pr->type; |
---|
228 | delete pr->embed; |
---|
229 | pr = (ListRec *)WinSendMsg( _this->hContainer, CM_QUERYRECORD, |
---|
230 | MPFROMP( pr ), MPFROM2SHORT( CMA_NEXT, CMA_ITEMORDER ) ); |
---|
231 | } |
---|
232 | WinSendMsg( _this->hContainer, CM_REMOVERECORD, |
---|
233 | MPFROMP( NULL ), MPFROM2SHORT( 0, CMA_FREE ) ); |
---|
234 | } |
---|
235 | break; |
---|
236 | |
---|
237 | } |
---|
238 | return WinDefDlgProc( hwnd, msg, mp1, mp2 ); |
---|
239 | } |
---|
240 | |
---|