source: trunk/Lucide/SOURCE/gui/pluginViewDlg.cpp @ 230

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