source: trunk/Lucide/gui/pluginViewDlg.cpp @ 399

Last change on this file since 399 was 367, checked in by dmik, 12 years ago

Merged bramches/kmk (r294:365) to trunk.

File size: 7.4 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 "globals.h"
38#include "luutils.h"
39#include "pluginViewDlg.h"
40#include "Lucide_res.h"
41#include "messages.h"
42
43
44PluginViewDlg::PluginViewDlg( HWND hWndFrame, PluginInfoList *plist )
45{
46    hFrame   = hWndFrame;
47    plugins  = plist;
48    pname    = newstrdupL( PLUGLIST_PLUGIN_NAME );
49    suppexts = newstrdupL( PLUGLIST_SUPP_EXTS );
50    pdesc    = newstrdupL( PLUGLIST_PLUGIN_DESC );
51}
52
53PluginViewDlg::~PluginViewDlg()
54{
55    delete pname;
56    delete suppexts;
57    delete pdesc;
58}
59
60void PluginViewDlg::doDialog()
61{
62    WinDlgBox( HWND_DESKTOP, hFrame, pluginViewDlgProc,
63               _hmod, IDD_VIEWPLUGINS, this );
64    delete this;
65}
66
67
68struct ListRec
69{
70    MINIRECORDCORE miniRecordCore;
71    PSZ extensions;
72    PSZ description;
73};
74
75
76MRESULT EXPENTRY PluginViewDlg::pluginViewDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
77{
78    // This is a static method, so we don't know which instantiation we're
79    // dealing with. But we can get a pseudo-this from the parameter to
80    // WM_INITDLG, which we therafter store with the window and retrieve
81    // as follows:
82    PluginViewDlg *_this = (PluginViewDlg *)WinQueryWindowULong( hwnd, QWL_USER );
83
84    switch (msg)
85    {
86
87        // Dialog has just been created
88        case WM_INITDLG:
89        {
90            // Save the mp2 into our user data so that subsequent calls have
91            // access to the parent C++ object
92            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
93            _this = (PluginViewDlg *)mp2;
94            localizeDialog( hwnd );
95            centerWindow( _this->hFrame, hwnd );
96
97            // init container
98            HWND cntr = WinWindowFromID( hwnd, IDC_PLUGINSLIST );
99            CNRINFO ci;
100            ci.cb = sizeof( CNRINFO );
101            WinSendMsg( cntr, CM_QUERYCNRINFO, MPFROMP( &ci ), MPFROMSHORT( ci.cb ) );
102            ci.flWindowAttr &= ~( CV_NAME | CV_FLOW | CV_TEXT | CV_ICON );
103            ci.flWindowAttr |= ( CV_DETAIL | CV_MINI | CA_DETAILSVIEWTITLES );
104            WinSendMsg( cntr, CM_SETCNRINFO, MPFROMP( &ci ), MPFROMLONG( CMA_FLWINDOWATTR ) );
105
106            PFIELDINFO pFieldInfo = (PFIELDINFO)WinSendMsg( cntr, CM_ALLOCDETAILFIELDINFO,
107                                             MPFROMSHORT( 3 ), MPVOID );
108            PFIELDINFO pFldInfo = pFieldInfo;
109            pFldInfo->cb = sizeof( FIELDINFO );
110            pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR;
111            pFldInfo->flTitle = CFA_CENTER;
112            pFldInfo->pTitleData = (PVOID)_this->pname;
113            pFldInfo->offStruct = FIELDOFFSET( ListRec, miniRecordCore.pszIcon );
114            pFldInfo = pFldInfo->pNextFieldInfo;
115            pFldInfo->cb = sizeof( FIELDINFO );
116            pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR;
117            pFldInfo->flTitle = CFA_CENTER;
118            pFldInfo->pTitleData = (PVOID)_this->suppexts;
119            pFldInfo->offStruct = FIELDOFFSET( ListRec, extensions );
120            pFldInfo = pFldInfo->pNextFieldInfo;
121            pFldInfo->cb = sizeof( FIELDINFO );
122            pFldInfo->flData = CFA_STRING | CFA_HORZSEPARATOR | CFA_SEPARATOR;
123            pFldInfo->flTitle = CFA_CENTER;
124            pFldInfo->pTitleData = (PVOID)_this->pdesc;
125            pFldInfo->offStruct = FIELDOFFSET( ListRec, description );
126
127            FIELDINFOINSERT fieldInfoInsert;
128            fieldInfoInsert.cb = sizeof( FIELDINFOINSERT );
129            fieldInfoInsert.pFieldInfoOrder = (PFIELDINFO)CMA_FIRST;
130            fieldInfoInsert.cFieldInfoInsert = 3;
131            fieldInfoInsert.fInvalidateFieldInfo = TRUE;
132            WinSendMsg( cntr, CM_INSERTDETAILFIELDINFO, MPFROMP( pFieldInfo ), MPFROMP( &fieldInfoInsert ) );
133
134            for ( int i = 0; i < _this->plugins->size(); i++ )
135            {
136                PluginInfo *pi = &(*_this->plugins)[ i ];
137
138                ListRec *r = (ListRec *)WinSendMsg( cntr, CM_ALLOCRECORD,
139                    MPFROMLONG( ( sizeof( ListRec ) - sizeof( MINIRECORDCORE ) ) ),
140                                            MPFROMSHORT( 1 ) );
141
142                r->miniRecordCore.cb = sizeof( MINIRECORDCORE );
143                r->miniRecordCore.flRecordAttr = 0;
144                r->miniRecordCore.ptlIcon.x = 0;
145                r->miniRecordCore.ptlIcon.y = 0;
146                r->miniRecordCore.pszIcon = newstrdup( pi->name.c_str() );
147                r->miniRecordCore.hptrIcon = NULLHANDLE;
148                r->extensions = newstrdup( pi->extensions.c_str() );
149                r->description = newstrdup( pi->description.c_str() );
150
151                RECORDINSERT ri;
152                ri.cb = sizeof( RECORDINSERT );
153                ri.pRecordParent= NULL;
154                ri.pRecordOrder = (PRECORDCORE)CMA_END;
155                ri.zOrder = (USHORT)CMA_TOP;
156                ri.cRecordsInsert = 1;
157                ri.fInvalidateRecord = TRUE;
158                WinSendMsg( cntr, CM_INSERTRECORD, MPFROMP( r ), MPFROMP( &ri ) );
159            }
160
161            return (MRESULT)FALSE;
162        }
163
164        case WM_DESTROY:
165        {
166            HWND cntr = WinWindowFromID( hwnd, IDC_PLUGINSLIST );
167            ListRec *pRecords = (ListRec *)WinSendMsg( cntr, CM_QUERYRECORD,
168                                MPFROMP( NULL ), MPFROM2SHORT( CMA_FIRST, CMA_ITEMORDER ) );
169            ListRec *pr = pRecords;
170
171            while ( pr != NULL )
172            {
173                delete pr->miniRecordCore.pszIcon;
174                delete pr->extensions;
175                delete pr->description;
176                pr = (ListRec *)WinSendMsg( cntr, CM_QUERYRECORD,
177                                    MPFROMP( pr ), MPFROM2SHORT( CMA_NEXT, CMA_ITEMORDER ) );
178            }
179            WinSendMsg( cntr, CM_REMOVERECORD, MPFROMP( NULL ), MPFROM2SHORT( 0, CMA_FREE ) );
180        }
181        break;
182
183    }
184    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
185}
186
187
Note: See TracBrowser for help on using the repository browser.