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

Last change on this file since 37 was 35, checked in by Eugene Romanenko, 16 years ago

added licence block to source files

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