source: trunk/Lucide/gui/docInfoDlg.cpp @ 459

Last change on this file since 459 was 459, checked in by Silvan Scherrer, 11 years ago

fixed ticket:207

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