source: trunk/Lucide/SOURCE/gui/printDlg.cpp @ 89

Last change on this file since 89 was 89, checked in by Eugene Romanenko, 15 years ago

UI improvements, started print dialog

File size: 7.5 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#define INCL_DEV
37#define INCL_ERRORS
38#define INCL_SPL
39#define INCL_SPLDOSPRINT
40#include <os2.h>
41
42#include <ludoc.xh>
43
44#include "printDlg.h"
45#include "Lucide_res.h"
46#include "luutils.h"
47
48extern HAB hab;
49
50#define DEVICENAME_LENGTH   32
51#define DRIVERNAME_LENGTH   128
52
53struct PrintDlgInternalData
54{
55    PPRQINFO3 pQueueInfo;
56    PPRQINFO3 pCurQueue;
57};
58
59
60PrintDlg::PrintDlg( HWND hWndFrame, LuDocument *_doc )
61{
62    hFrame = hWndFrame;
63    doc    = _doc;
64    data   = new PrintDlgInternalData;
65    memset( data, 0, sizeof( PrintDlgInternalData ) );
66}
67
68PrintDlg::~PrintDlg()
69{
70    if ( data->pQueueInfo != NULL ) {
71        free( data->pQueueInfo );
72    }
73    delete data;
74}
75
76ULONG PrintDlg::showDialog()
77{
78    return WinDlgBox( HWND_DESKTOP, hFrame, printDlgProc,
79                      NULLHANDLE, IDD_PRINT, this );
80}
81
82
83void PrintDlg::setCurrentQInfo( HWND hwnd, void *i )
84{
85    data->pCurQueue = (PPRQINFO3)i;
86    WinSetDlgItemText( hwnd, IDC_PNAME, data->pCurQueue->pszComment );
87    WinSetDlgItemText( hwnd, IDC_PDESCRIPTION, data->pCurQueue->pszDriverName );
88    WinEnableControl( hwnd, IDC_JOBPROPERTIES, TRUE );
89    WinEnableControl( hwnd, DID_OK, TRUE );
90}
91
92void PrintDlg::enumQueues( HWND hwnd )
93{
94    HWND list = WinWindowFromID( hwnd, IDC_PNAME );
95    ULONG cReturned = 0, cTotal = 0, cbNeeded = 0;
96    SPLERR se = SplEnumQueue( NULL, 3, NULL, 0L, &cReturned,
97                              &cTotal, &cbNeeded, NULL );
98    if ( cTotal == 0L ) {
99        // TODO: 'no printers installed' message
100    }
101
102    data->pQueueInfo = (PPRQINFO3)malloc( cbNeeded );
103
104    se = SplEnumQueue( NULL, 3, data->pQueueInfo, cbNeeded, &cReturned,
105                       &cTotal, &cbNeeded, NULL );
106    if ( se != NO_ERROR ) {
107        // TODO: error message
108        free( data->pQueueInfo );
109        data->pQueueInfo = NULL;
110        return;
111    }
112
113    USHORT sEntry;
114    for ( ULONG i = 0; i < cReturned; i++ )
115    {
116        sEntry = (SHORT)WinSendMsg( list, LM_INSERTITEM, MPFROMSHORT(LIT_END),
117                                    MPFROMP( data->pQueueInfo[i].pszComment ) );
118        WinSendMsg( list, LM_SETITEMHANDLE,
119                    MPFROMSHORT(sEntry), MPFROMP( &(data->pQueueInfo[i]) ) );
120
121        if ( data->pQueueInfo[i].fsType & PRQ3_TYPE_APPDEFAULT ) {
122            setCurrentQInfo( hwnd, &( data->pQueueInfo[i] ) );
123        }
124    }
125}
126
127
128void PrintDlg::showJobProperties()
129{
130    if ( data->pCurQueue == NULL ) {
131        return;
132    }
133
134    char achDriverName[ DRIVERNAME_LENGTH ];
135    char achDeviceName[ DEVICENAME_LENGTH ];
136
137    // The pszDriverName is of the form DRIVER.DEVICE (e.g.,
138    // LASERJET.HP LaserJet IID) so we need to separate it at the dot
139    int i = strcspn( data->pCurQueue->pszDriverName, "." );
140    if ( i > 0 ) {
141        strncpy( achDriverName, data->pCurQueue->pszDriverName, i );
142        achDriverName[ i ] = '\0';
143        strcpy( achDeviceName, &( data->pCurQueue->pszDriverName[ i + 1 ] ) );
144    }
145    else {
146        strcpy( achDriverName, data->pCurQueue->pszDriverName );
147        *achDeviceName = '\0';
148    }
149
150    // There may be more than one printer assigned to this print queue
151    // We will use the first in the comma separated list.  We would
152    // need an expanded dialog for the user to be more specific.
153    char *pszTemp = strchr( data->pCurQueue->pszPrinters, ',' );
154    if ( pszTemp != NULL ) {
155        // Strip off comma and trailing printer names
156        *pszTemp = '\0' ;
157    }
158
159    // Post the job properties dialog for the printer to allow the
160    // user to modify the options
161    DevPostDeviceModes( hab, data->pCurQueue->pDriverData, achDriverName,
162                        achDeviceName, data->pCurQueue->pszPrinters, DPDM_POSTJOBPROP );
163}
164
165
166MRESULT EXPENTRY PrintDlg::printDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
167{
168    // This is a static method, so we don't know which instantiation we're
169    // dealing with. But we can get a pseudo-this from the parameter to
170    // WM_INITDLG, which we therafter store with the window and retrieve
171    // as follows:
172    PrintDlg *_this = (PrintDlg *)WinQueryWindowULong( hwnd, QWL_USER );
173
174    switch (msg)
175    {
176
177        // Dialog has just been created
178        case WM_INITDLG:
179        {
180            // Save the mp2 into our user data so that subsequent calls have
181            // access to the parent C++ object
182            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
183            _this = (PrintDlg *)mp2;
184            localizeDialog( hwnd );
185            centerWindow( _this->hFrame, hwnd );
186            _this->enumQueues( hwnd );
187            return (MRESULT)FALSE;
188        }
189
190        case WM_CONTROL:
191        {
192            if ( (SHORT1FROMMP(mp1) == IDC_PNAME) && (SHORT2FROMMP(mp1) == CBN_ENTER) )
193            {
194                SHORT rc = (SHORT)WinSendDlgItemMsg( hwnd, IDC_PNAME, LM_QUERYSELECTION,
195                                                     MPFROMSHORT( LIT_CURSOR ), MPVOID );
196                if ( rc != LIT_NONE ) {
197                    MRESULT r = WinSendDlgItemMsg( hwnd, IDC_PNAME, LM_QUERYITEMHANDLE,
198                                                   MPFROMSHORT( rc ), MPVOID );
199                    _this->setCurrentQInfo( hwnd, r );
200                }
201            }
202        }
203        break;
204
205        case WM_COMMAND:
206            switch (SHORT1FROMMP(mp1))
207            {
208                case IDC_JOBPROPERTIES:
209                    _this->showJobProperties();
210                    return (MRESULT)FALSE;
211
212                case DID_OK:
213                    {
214                        // do
215                        WinDismissDlg( hwnd, DID_OK );
216                    }
217                    return (MRESULT)FALSE;
218
219                case DID_CANCEL:
220                    WinDismissDlg( hwnd, DID_CANCEL );
221                    return (MRESULT)FALSE;
222            };
223            return (MRESULT)FALSE;
224    }
225    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
226}
227
228
Note: See TracBrowser for help on using the repository browser.