source: trunk/Lucide/SOURCE/gui/docInfoDlg.cpp @ 150

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

Better solution for #78, move GUI to DLL, executor sets BeginLibPath? and loads GUI DLL (closes #78)

File size: 7.7 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 <string>
39
40#include <ludoc.xh>
41
42#include "globals.h"
43#include "luutils.h"
44#include "docInfoDlg.h"
45#include "Lucide_res.h"
46#include "messages.h"
47
48
49DocInfoDlg::DocInfoDlg( HWND hWndFrame, LuDocumentInfo *_dinfo )
50{
51    hFrame   = hWndFrame;
52    dinfo    = _dinfo;
53}
54
55DocInfoDlg::~DocInfoDlg()
56{
57}
58
59void DocInfoDlg::doDialog()
60{
61    WinDlgBox( HWND_DESKTOP, hFrame, docInfoDlgProc,
62               _hmod, IDD_DOCINFO, this );
63    delete this;
64}
65
66
67struct ListRec
68{
69    MINIRECORDCORE miniRecordCore;
70    PSZ value;
71};
72
73
74void DocInfoDlg::insertPair( HWND cntr, const char *key, const char *value )
75{
76    ListRec *r = (ListRec *)WinSendMsg( cntr, CM_ALLOCRECORD,
77        MPFROMLONG( ( sizeof( ListRec ) - sizeof( MINIRECORDCORE ) ) ),
78                                MPFROMSHORT( 1 ) );
79
80    r->miniRecordCore.cb = sizeof( MINIRECORDCORE );
81    r->miniRecordCore.flRecordAttr = 0;
82    r->miniRecordCore.ptlIcon.x = 0;
83    r->miniRecordCore.ptlIcon.y = 0;
84    r->miniRecordCore.pszIcon = newstrdupL( key );
85    r->miniRecordCore.hptrIcon = NULLHANDLE;
86    r->value = newstrdup( value );
87
88    RECORDINSERT ri;
89    ri.cb = sizeof( RECORDINSERT );
90    ri.pRecordParent= NULL;
91    ri.pRecordOrder = (PRECORDCORE)CMA_END;
92    ri.zOrder = (USHORT)CMA_TOP;
93    ri.cRecordsInsert = 1;
94    ri.fInvalidateRecord = TRUE;
95    WinSendMsg( cntr, CM_INSERTRECORD, MPFROMP( r ), MPFROMP( &ri ) );
96}
97
98
99void DocInfoDlg::loadValues( HWND cntr )
100{
101    if ( dinfo == NULL ) {
102        return;
103    }
104
105    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_TITLE ) {
106        insertPair( cntr, DOCINFO_TITLE, dinfo->title );
107    }
108    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_FORMAT ) {
109        insertPair( cntr, DOCINFO_FORMAT, dinfo->format );
110    }
111    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_AUTHOR ) {
112        insertPair( cntr, DOCINFO_AUTHOR, dinfo->author );
113    }
114    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_SUBJECT ) {
115        insertPair( cntr, DOCINFO_SUBJECT, dinfo->subject );
116    }
117    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_KEYWORDS ) {
118        insertPair( cntr, DOCINFO_KEYWORDS, dinfo->keywords );
119    }
120    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_CREATOR ) {
121        insertPair( cntr, DOCINFO_CREATOR, dinfo->creator );
122    }
123    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_PRODUCER ) {
124        insertPair( cntr, DOCINFO_PRODUCER, dinfo->producer );
125    }
126    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_CREATION_DATE ) {
127        insertPair( cntr, DOCINFO_CREATION_DATE,
128                    time2string( dinfo->creation_date ).c_str() );
129    }
130    if ( dinfo->fields_mask & LU_DOCUMENT_INFO_MOD_DATE ) {
131        insertPair( cntr, DOCINFO_MOD_DATE,
132                    time2string( dinfo->modified_date ).c_str() );
133    }
134}
135
136
137MRESULT EXPENTRY DocInfoDlg::docInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
138{
139    // This is a static method, so we don't know which instantiation we're
140    // dealing with. But we can get a pseudo-this from the parameter to
141    // WM_INITDLG, which we therafter store with the window and retrieve
142    // as follows:
143    DocInfoDlg *_this = (DocInfoDlg *)WinQueryWindowULong( hwnd, QWL_USER );
144
145    switch (msg)
146    {
147
148        // Dialog has just been created
149        case WM_INITDLG:
150        {
151            // Save the mp2 into our user data so that subsequent calls have
152            // access to the parent C++ object
153            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
154            _this = (DocInfoDlg *)mp2;
155            localizeDialog( hwnd );
156            centerWindow( _this->hFrame, hwnd );
157
158            // init container
159            HWND cntr = WinWindowFromID( hwnd, IDC_PROPSLIST );
160            CNRINFO ci;
161            ci.cb = sizeof( CNRINFO );
162            WinSendMsg( cntr, CM_QUERYCNRINFO, MPFROMP( &ci ), MPFROMSHORT( ci.cb ) );
163            ci.flWindowAttr &= ~( CV_NAME | CV_FLOW | CV_TEXT | CV_ICON | CA_DETAILSVIEWTITLES );
164            ci.flWindowAttr |= ( CV_DETAIL | CV_MINI );
165            WinSendMsg( cntr, CM_SETCNRINFO, MPFROMP( &ci ), MPFROMLONG( CMA_FLWINDOWATTR ) );
166
167            PFIELDINFO pFieldInfo = (PFIELDINFO)WinSendMsg( cntr, CM_ALLOCDETAILFIELDINFO,
168                                             MPFROMSHORT( 2 ), MPVOID );
169            PFIELDINFO pFldInfo = pFieldInfo;
170            pFldInfo->cb = sizeof( FIELDINFO );
171            pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR;
172            pFldInfo->flTitle = CFA_CENTER;
173            pFldInfo->pTitleData = NULL;
174            pFldInfo->offStruct = FIELDOFFSET( ListRec, miniRecordCore.pszIcon );
175            pFldInfo = pFldInfo->pNextFieldInfo;
176            pFldInfo->cb = sizeof( FIELDINFO );
177            pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR;
178            pFldInfo->flTitle = CFA_CENTER;
179            pFldInfo->pTitleData = NULL;
180            pFldInfo->offStruct = FIELDOFFSET( ListRec, value );
181
182            FIELDINFOINSERT fieldInfoInsert;
183            fieldInfoInsert.cb = sizeof( FIELDINFOINSERT );
184            fieldInfoInsert.pFieldInfoOrder = (PFIELDINFO)CMA_FIRST;
185            fieldInfoInsert.cFieldInfoInsert = 2;
186            fieldInfoInsert.fInvalidateFieldInfo = TRUE;
187            WinSendMsg( cntr, CM_INSERTDETAILFIELDINFO,
188                   MPFROMP( pFieldInfo ), MPFROMP( &fieldInfoInsert ) );
189
190            _this->loadValues( cntr );
191
192            return (MRESULT)FALSE;
193        }
194
195        case WM_DESTROY:
196        {
197            HWND cntr = WinWindowFromID( hwnd, IDC_PROPSLIST );
198            ListRec *pRecords = (ListRec *)WinSendMsg( cntr, CM_QUERYRECORD,
199                                MPFROMP( NULL ), MPFROM2SHORT( CMA_FIRST, CMA_ITEMORDER ) );
200            ListRec *pr = pRecords;
201
202            while ( pr != NULL )
203            {
204                delete pr->miniRecordCore.pszIcon;
205                delete pr->value;
206                pr = (ListRec *)WinSendMsg( cntr, CM_QUERYRECORD,
207                                    MPFROMP( pr ), MPFROM2SHORT( CMA_NEXT, CMA_ITEMORDER ) );
208            }
209            WinSendMsg( cntr, CM_REMOVERECORD, MPFROMP( NULL ), MPFROM2SHORT( 0, CMA_FREE ) );
210        }
211        break;
212
213    }
214    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
215}
216
217
Note: See TracBrowser for help on using the repository browser.