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

Last change on this file since 563 was 563, checked in by Gregg Young, 5 years ago

Added "help" menu items and added context sensitive help to the dialogs. F1 brings up help most everywhere. Ticket #12 Prevent thumbnail creation on encrypted files. Make thumbnail optional globally and on a per file basis. Tickets #263 #267

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