-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
211 lines (183 loc) · 9.71 KB
/
menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*********************************************************************
* *
* MODULE NAME : menu.c AUTHOR: Rick Fishman *
* DATE WRITTEN: 07-22-93 *
* *
* MODULE DESCRIPTION: *
* *
* Part of the 'DRGDROP' drag/drop sample program. *
* *
* This module takes care of creating and destroying the container *
* context menu. *
* *
* NOTES: *
* *
* *
* FUNCTIONS AVALABLE TO OTHER MODULES: *
* *
* menuCreate *
* menuEnd *
* *
* *
* HISTORY: *
* *
* 07-22-93 - Program coded. *
* *
* Rick Fishman *
* Code Blazers, Inc. *
* 4113 Apricot *
* Irvine, CA. 92720 *
* CIS ID: 72251,750 *
* *
*********************************************************************/
#pragma strings(readonly) // used for debug version of memory mgmt routines
/*********************************************************************/
/*------- Include relevant sections of the OS/2 header files --------*/
/*********************************************************************/
#define INCL_WINERRORS
#define INCL_WINFRAMEMGR
#define INCL_WINMENUS
#define INCL_WINPOINTERS
#define INCL_WINSTDCNR
#define INCL_WINSTDDRAG
#define INCL_WINWINDOWMGR
/**********************************************************************/
/*----------------------------- INCLUDES -----------------------------*/
/**********************************************************************/
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "drgdrop.h"
/*********************************************************************/
/*------------------- APPLICATION DEFINITIONS -----------------------*/
/*********************************************************************/
/**********************************************************************/
/*---------------------------- STRUCTURES ----------------------------*/
/**********************************************************************/
/**********************************************************************/
/*----------------------- FUNCTION PROTOTYPES ------------------------*/
/**********************************************************************/
/**********************************************************************/
/*------------------------ GLOBAL VARIABLES --------------------------*/
/**********************************************************************/
HWND hwndMenu;
/**********************************************************************/
/*--------------------------- menuCreate -----------------------------*/
/* */
/* CREATE AND POSITION THE CONTEXT MENU. */
/* */
/* PARMS: frame window handle */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void menuCreate( HWND hwndFrame )
{
if( !hwndMenu || !WinIsWindow( ANCHOR( hwndFrame ), hwndMenu ) )
hwndMenu = WinLoadMenu( hwndFrame, 0, ID_CONTEXT_MENU );
if( hwndMenu )
{
POINTL ptl;
// Get the position of the mouse pointer
if( WinQueryPointerPos( HWND_DESKTOP, &ptl ) )
{
// Convert the position of the mouse pointer to coordinates with
// respect to the frame window.
if( WinMapWindowPoints( HWND_DESKTOP, hwndFrame, &ptl, 1 ) )
{
if( WinPopupMenu( hwndFrame, hwndFrame, hwndMenu, ptl.x, ptl.y,
0, PU_HCONSTRAIN | PU_VCONSTRAIN |
PU_KEYBOARD | PU_MOUSEBUTTON1 |
PU_MOUSEBUTTON2 | PU_NONE ) )
{
// If you don't do this PM will assign a menu id of
// FID_MENU.
WinSetWindowUShort( hwndMenu, QWS_ID, ID_CONTEXT_MENU );
}
else
Msg( "menuCreate WinPopupMenu failed! RC(%X)",
HWNDERR( hwndFrame ) );
}
else
Msg( "menuCreate WinMapWindowPoints failed! RC(%X)",
HWNDERR( hwndFrame ) );
}
else
Msg( "menuCreate WinQueryPointerPos failed! RC(%X)",
HWNDERR( hwndFrame ) );
}
else
Msg( "menuCreate could not load the context menu. RC(%X)",
HWNDERR( hwndFrame ) );
}
/**********************************************************************/
/*----------------------------- menuEnd ------------------------------*/
/* */
/* DESTROY THE MENU ON A WM_MENUEND MESSAGE. */
/* */
/* PARMS: frame window handle, */
/* menu id */
/* menu window handle */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void menuEnd( HWND hwndFrame, ULONG idMenu, HWND hwndMenu )
{
if( idMenu == ID_CONTEXT_MENU && hwndMenu )
{
// After the menu is gone the container no longer has the focus so we
// have to reset it.
WinSetFocus( HWND_DESKTOP, WinWindowFromID( hwndFrame, FID_CLIENT ) );
}
}
/**********************************************************************/
/*--------------------------- menuCommand ----------------------------*/
/* */
/* PROCESS A WM_COMMAND MESSAGE GENERATED FROM THE MENU. */
/* */
/* PARMS: frame window handle, */
/* command id */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void menuCommand( HWND hwndFrame, ULONG idCommand )
{
switch( idCommand )
{
case IDM_DRAGINFO_SETTINGS:
bookSetup( NBPID_DRAGINFO );
break;
case IDM_RMF_SETTINGS:
bookSetup( NBPID_RMF );
break;
case IDM_REPLY_SETTINGS:
bookSetup( NBPID_REPLY );
break;
case IDM_MISC_SETTINGS:
bookSetup( NBPID_MISC );
break;
case IDM_SURFACE_LISTBOX:
WinSetActiveWindow( HWND_DESKTOP,
INSTDATA( hwndFrame )->hwndDebug );
break;
case IDM_EXIT:
WinPostMsg( hwndFrame, WM_SYSCOMMAND, MPFROMSHORT( SC_CLOSE ),
MPFROM2SHORT( CMDSRC_ACCELERATOR, FALSE ) );
break;
}
}
/*************************************************************************
* E N D O F S O U R C E *
*************************************************************************/