source: trunk/Lucide/SOURCE/gui/fontsInfoDlg.cpp @ 94

Last change on this file since 94 was 91, checked in by Eugene Romanenko, 15 years ago

bitmap printing, preliminary postscript printing, export to PS for djvu plugin, other improvements

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