source: branches/kmk/Lucide/gui/fontsInfoDlg.cpp @ 334

Last change on this file since 334 was 334, checked in by dmik, 11 years ago

branches/kmk: Renamed private os2.h to os2all.h to avoid the clash with the toolkit one.

File size: 8.8 KB
Line 
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#include "os2all.h"
36
37#include <process.h>
38
39#include <ludoc.xh>
40
41#include "globals.h"
42#include "luutils.h"
43#include "fontsInfoDlg.h"
44#include "Lucide_res.h"
45#include "messages.h"
46
47
48FontsInfoDlg::FontsInfoDlg( HWND hWndFrame, LuDocument *_doc )
49{
50    hFrame     = hWndFrame;
51    doc        = _doc;
52    hDialog    = NULLHANDLE;
53    hContainer = NULLHANDLE;
54    name       = newstrdupL( FONTINFO_NAME );
55    type       = newstrdupL( FONTINFO_TYPE );
56    embed      = newstrdupL( FONTINFO_EMBEDDED );
57    emb_notembedded    = newstrdupL( FONTINFO_EMBED_NOT_EMBEDDED );
58    emb_embedded       = newstrdupL( FONTINFO_EMBED_EMBEDDED );
59    emb_embeddedsubset = newstrdupL( FONTINFO_EMBED_EMBEDDED_SUBSET );
60}
61
62FontsInfoDlg::~FontsInfoDlg()
63{
64    delete name;
65    delete type;
66    delete embed;
67    delete emb_notembedded;
68    delete emb_embedded;
69    delete emb_embeddedsubset;
70}
71
72void FontsInfoDlg::doDialog()
73{
74    WinDlgBox( HWND_DESKTOP, hFrame, fontsInfoDlgProc,
75               _hmod, IDD_FONTINFO, this );
76    delete this;
77}
78
79
80struct ListRec
81{
82    MINIRECORDCORE miniRecordCore;
83    PSZ type;
84    PSZ embed;
85};
86
87
88void FontsInfoDlg::loadList()
89{
90    LuDocument_LuFontInfoSequence *fonts = doc->getFontInfo( ev );
91
92    if ( fonts != NULL )
93    {
94        for ( int i = 0; i < fonts->_length; i++ )
95        {
96            ListRec *r = (ListRec *)WinSendMsg( hContainer, CM_ALLOCRECORD,
97              MPFROMLONG( ( sizeof( ListRec ) - sizeof( MINIRECORDCORE ) ) ),
98                                      MPFROMSHORT( 1 ) );
99
100            r->miniRecordCore.cb = sizeof( MINIRECORDCORE );
101            r->miniRecordCore.flRecordAttr = 0;
102            r->miniRecordCore.ptlIcon.x = 0;
103            r->miniRecordCore.ptlIcon.y = 0;
104            r->miniRecordCore.pszIcon = newstrdup( fonts->_buffer[i].name );
105            r->miniRecordCore.hptrIcon = NULLHANDLE;
106            r->type = newstrdup( fonts->_buffer[i].type );
107            r->embed = NULL;
108            switch ( fonts->_buffer[i].embedded )
109            {
110                case LU_FONTEMBED_NOT_EMBEDDED:
111                    r->embed = newstrdup( emb_notembedded );
112                    break;
113                case LU_FONTEMBED_EMBEDDED:
114                    r->embed = newstrdup( emb_embedded );
115                    break;
116                case LU_FONTEMBED_EMBEDDED_SUBSET:
117                    r->embed = newstrdup( emb_embeddedsubset );
118                    break;
119            }
120
121            RECORDINSERT ri;
122            ri.cb = sizeof( RECORDINSERT );
123            ri.pRecordParent= NULL;
124            ri.pRecordOrder = (PRECORDCORE)CMA_END;
125            ri.zOrder = (USHORT)CMA_TOP;
126            ri.cRecordsInsert = 1;
127            ri.fInvalidateRecord = TRUE;
128            WinSendMsg( hContainer, CM_INSERTRECORD, MPFROMP( r ), MPFROMP( &ri ) );
129        }
130
131        LuDocument::freeFontInfo( ev, fonts );
132    }
133}
134
135void FontsInfoDlg::loadthread( void *p )
136{
137    FontsInfoDlg *_this = (FontsInfoDlg *)p;
138    HAB thab = WinInitialize( 0 );
139    HMQ thmq = WinCreateMsgQueue( thab, 0 );
140
141    _this->loadList();
142
143    WinSetDlgItemText( _this->hDialog, IDC_ENUMLABEL, "" );
144    WinEnableControl( _this->hDialog, DID_OK, TRUE );
145    WinInvalidateRect( _this->hDialog, NULL, TRUE );
146
147    WinDestroyMsgQueue( thmq );
148    WinTerminate( thab );
149    _endthread();
150}
151
152MRESULT EXPENTRY FontsInfoDlg::fontsInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
153{
154    // This is a static method, so we don't know which instantiation we're
155    // dealing with. But we can get a pseudo-this from the parameter to
156    // WM_INITDLG, which we therafter store with the window and retrieve
157    // as follows:
158    FontsInfoDlg *_this = (FontsInfoDlg *)WinQueryWindowULong( hwnd, QWL_USER );
159
160    switch (msg)
161    {
162
163        // Dialog has just been created
164        case WM_INITDLG:
165        {
166            // Save the mp2 into our user data so that subsequent calls have
167            // access to the parent C++ object
168            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
169            _this = (FontsInfoDlg *)mp2;
170            _this->hDialog = hwnd;
171            _this->hContainer = WinWindowFromID( hwnd, IDC_FONTSLIST );
172            localizeDialog( hwnd );
173            centerWindow( _this->hFrame, hwnd );
174
175            // init container
176            CNRINFO ci;
177            ci.cb = sizeof( CNRINFO );
178            WinSendMsg( _this->hContainer, CM_QUERYCNRINFO, MPFROMP( &ci ), MPFROMSHORT( ci.cb ) );
179            ci.flWindowAttr &= ~( CV_NAME | CV_FLOW | CV_TEXT | CV_ICON );
180            ci.flWindowAttr |= ( CV_DETAIL | CV_MINI | CA_DETAILSVIEWTITLES );
181            WinSendMsg( _this->hContainer, CM_SETCNRINFO, MPFROMP( &ci ), MPFROMLONG( CMA_FLWINDOWATTR ) );
182
183            PFIELDINFO pFieldInfo = (PFIELDINFO)WinSendMsg( _this->hContainer, CM_ALLOCDETAILFIELDINFO,
184                                             MPFROMSHORT( 3 ), MPVOID );
185            PFIELDINFO pFldInfo = pFieldInfo;
186            pFldInfo->cb = sizeof( FIELDINFO );
187            pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR;
188            pFldInfo->flTitle = CFA_CENTER;
189            pFldInfo->pTitleData = (PVOID)_this->name;
190            pFldInfo->offStruct = FIELDOFFSET( ListRec, miniRecordCore.pszIcon );
191            pFldInfo = pFldInfo->pNextFieldInfo;
192            pFldInfo->cb = sizeof( FIELDINFO );
193            pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR;
194            pFldInfo->flTitle = CFA_CENTER;
195            pFldInfo->pTitleData = (PVOID)_this->type;
196            pFldInfo->offStruct = FIELDOFFSET( ListRec, type );
197            pFldInfo = pFldInfo->pNextFieldInfo;
198            pFldInfo->cb = sizeof( FIELDINFO );
199            pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR;
200            pFldInfo->flTitle = CFA_CENTER;
201            pFldInfo->pTitleData = (PVOID)_this->embed;
202            pFldInfo->offStruct = FIELDOFFSET( ListRec, embed );
203
204            FIELDINFOINSERT fieldInfoInsert;
205            fieldInfoInsert.cb = sizeof( FIELDINFOINSERT );
206            fieldInfoInsert.pFieldInfoOrder = (PFIELDINFO)CMA_FIRST;
207            fieldInfoInsert.cFieldInfoInsert = 3;
208            fieldInfoInsert.fInvalidateFieldInfo = TRUE;
209            WinSendMsg( _this->hContainer, CM_INSERTDETAILFIELDINFO,
210                        MPFROMP( pFieldInfo ), MPFROMP( &fieldInfoInsert ) );
211
212            _beginthread( loadthread, NULL, 32768, _this );
213
214            return (MRESULT)FALSE;
215        }
216
217        case WM_DESTROY:
218        {
219            ListRec *pRecords = (ListRec *)WinSendMsg( _this->hContainer, CM_QUERYRECORD,
220                                MPFROMP( NULL ), MPFROM2SHORT( CMA_FIRST, CMA_ITEMORDER ) );
221            ListRec *pr = pRecords;
222
223            while ( pr != NULL )
224            {
225                delete pr->miniRecordCore.pszIcon;
226                delete pr->type;
227                delete pr->embed;
228                pr = (ListRec *)WinSendMsg( _this->hContainer, CM_QUERYRECORD,
229                                    MPFROMP( pr ), MPFROM2SHORT( CMA_NEXT, CMA_ITEMORDER ) );
230            }
231            WinSendMsg( _this->hContainer, CM_REMOVERECORD,
232                        MPFROMP( NULL ), MPFROM2SHORT( 0, CMA_FREE ) );
233        }
234        break;
235
236    }
237    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
238}
239
Note: See TracBrowser for help on using the repository browser.