source: branches/kmk/Lucide/gui/pipemon.cpp @ 334

Last change on this file since 334 was 334, checked in by dmik, 11 years ago

branches/kmk: Renamed private os2.h to os2all.h to avoid the clash with the toolkit one.

File size: 5.8 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.h>
38#include <process.h>
39#include <stdlib.h>
40
41#include "Lucide_res.h"
42
43
44static const char *pipeName    = "\\PIPE\\LUCIDE";
45
46// Commands
47static const char *cmPrev       = "$prev";
48static const char *cmNext       = "$next";
49static const char *cmMinimize   = "$minimize";
50static const char *cmFullScreen = "$switchfullscreen";
51static const char *cmRotate     = "$rotate";
52static const char *cmZoomIn     = "$zoomin";
53static const char *cmZoomOut    = "$zoomout";
54static const char *cmZoomOrig   = "$zoomoriginal";
55
56
57static void pipeMonitor( void *p )
58{
59    HWND hWndFrame = (HWND)p;
60
61    HAB thab = WinInitialize( 0 );
62    HMQ hmq = WinCreateMsgQueue( thab, 0 );
63
64    char buf[ 100 ]  = "";
65    HPIPE PipeHandle = NULLHANDLE;
66    ULONG Readed     = 0;
67
68    if ( DosCreateNPipe( pipeName, &PipeHandle,
69                         NP_ACCESS_INBOUND | NP_NOINHERIT,
70                         NP_WAIT | NP_TYPE_MESSAGE | NP_READMODE_MESSAGE | 0x01,
71                         0, sizeof( buf ), 0 ) == 0 )
72    {
73        while ( true )
74        {
75            Readed = 0;
76            if ( DosConnectNPipe( PipeHandle ) != 0 ) {
77                break;
78            }
79            if ( DosRead( PipeHandle, buf, sizeof( buf ) - 1, &Readed ) == 0 )
80            {
81                if ( Readed != 0 )
82                {
83                    buf[ Readed ] = '\0';
84
85                    if ( strnicmp( buf, cmPrev, strlen( cmPrev ) ) == 0 )
86                    {
87                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_PREVPAGE ),
88                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
89                    }
90                    else if ( strnicmp( buf, cmNext, strlen( cmNext ) ) == 0 )
91                    {
92                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_NEXTPAGE ),
93                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
94                    }
95                    else if ( strnicmp( buf, cmMinimize, strlen( cmMinimize ) ) == 0 )
96                    {
97                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_MINIMIZE ),
98                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
99                    }
100                    else if ( strnicmp( buf, cmFullScreen, strlen( cmFullScreen ) ) == 0 )
101                    {
102                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_TOFULLSCREEN ),
103                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
104                    }
105                    else if ( strnicmp( buf, cmRotate, strlen( cmRotate ) ) == 0 )
106                    {
107                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_ROTATE90CW ),
108                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
109                    }
110                    else if ( strnicmp( buf, cmZoomIn, strlen( cmZoomIn ) ) == 0 )
111                    {
112                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_ZOOM_IN ),
113                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
114                    }
115                    else if ( strnicmp( buf, cmZoomOut, strlen( cmZoomOut ) ) == 0 )
116                    {
117                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_ZOOM_OUT ),
118                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
119                    }
120                    else if ( strnicmp( buf, cmZoomOrig, strlen( cmZoomOrig ) ) == 0 )
121                    {
122                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_ACTSIZE ),
123                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
124                    }
125                }
126            }
127            DosDisConnectNPipe( PipeHandle );
128        }
129
130        DosClose( PipeHandle );
131    }
132
133    WinDestroyMsgQueue( hmq );
134    WinTerminate( thab );
135}
136
137
138static int pmTid = -1;
139
140void initPipeMon( HWND hWndFrame )
141{
142    if ( pmTid == -1 ) {
143        pmTid = _beginthread( pipeMonitor, NULL, 32768, (void *)hWndFrame );
144    }
145}
146
147void unInitPipeMon()
148{
149    if ( pmTid != -1 ) {
150        TID tid = pmTid;
151        DosKillThread( tid );
152        DosWaitThread( &tid, DCWW_WAIT );
153    }
154}
155
Note: See TracBrowser for help on using the repository browser.