OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [mac/] [tkMacMenus.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tkMacMenus.c --
3
 *
4
 *      These calls set up and manage the menubar for the
5
 *      Macintosh version of Tk.
6
 *
7
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 * RCS: @(#) $Id: tkMacMenus.c,v 1.1.1.1 2002-01-16 10:25:56 markom Exp $
13
 */
14
 
15
#include "tcl.h"
16
#include "tclMacInt.h"
17
#include "tk.h"
18
#include "tkInt.h"
19
#include "tkMacInt.h"
20
 
21
/*
22
 * The define Status defined by Xlib.h conflicts with the function Status
23
 * defined by Devices.h.  We undefine it here to compile.
24
 */
25
#undef Status
26
#include <Devices.h>
27
#include <Menus.h>
28
#include <Memory.h>
29
#include <SegLoad.h>
30
#include <StandardFile.h>
31
#include <ToolUtils.h>
32
#include <Balloons.h>
33
 
34
#define kAppleMenu              256
35
#define kAppleAboutItem         1
36
#define kFileMenu               2
37
#define kEditMenu               3
38
 
39
#define kSourceItem             1
40
#define kCloseItem              2
41
#define kQuitItem               4
42
 
43
#define EDIT_CUT                1
44
#define EDIT_COPY               2
45
#define EDIT_PASTE              3
46
#define EDIT_CLEAR              4
47
 
48
MenuHandle tkAppleMenu;
49
MenuHandle tkFileMenu;
50
MenuHandle tkEditMenu;
51
 
52
static Tcl_Interp *     gInterp;        /* Interpreter for this application. */
53
 
54
static void GenerateEditEvent _ANSI_ARGS_((int flag));
55
static void SourceDialog _ANSI_ARGS_((void));
56
 
57
/*
58
 *----------------------------------------------------------------------
59
 *
60
 * TkMacHandleMenuSelect --
61
 *
62
 *      Handles events that occur in the Menu bar.
63
 *
64
 * Results:
65
 *      None.
66
 *
67
 * Side effects:
68
 *      None.
69
 *
70
 *----------------------------------------------------------------------
71
 */
72
 
73
void
74
TkMacHandleMenuSelect(
75
    long mResult,
76
    int optionKeyPressed)
77
{
78
    short theItem = LoWord(mResult);
79
    short theMenu = HiWord(mResult);
80
    Str255 name;
81
    Tk_Window tkwin;
82
    Window window;
83
 
84
    if (mResult == 0) {
85
        TkMacHandleTearoffMenu();
86
        TkMacClearMenubarActive();
87
        return;
88
    }
89
 
90
    switch (theMenu) {
91
 
92
        case kAppleMenu:
93
            switch (theItem) {
94
                case kAppleAboutItem:
95
                    {
96
                        Tcl_CmdInfo dummy;
97
 
98
                        if (optionKeyPressed || gInterp == NULL ||
99
                            Tcl_GetCommandInfo(gInterp,
100
                                    "tkAboutDialog", &dummy) == 0) {
101
                            TkAboutDlg();
102
                        } else {
103
                            Tcl_Eval(gInterp, "tkAboutDialog");
104
                        }
105
                        break;
106
                    }
107
                default:
108
                    GetItem(tkAppleMenu, theItem, name);
109
                    HiliteMenu(0);
110
                    OpenDeskAcc(name);
111
                    return;
112
            }
113
            break;
114
        case kFileMenu:
115
            switch (theItem) {
116
                case kSourceItem:
117
                    /* TODO: source script */
118
                    SourceDialog();
119
                    break;
120
                case kCloseItem:
121
                    /* Send close event */
122
                    window = TkMacGetXWindow(FrontWindow());
123
                    tkwin = Tk_IdToWindow(tkDisplayList->display, window);
124
                    TkGenWMDestroyEvent(tkwin);
125
                    break;
126
                case kQuitItem:
127
                    /* Exit */
128
                    if (optionKeyPressed || gInterp == NULL) {
129
                        Tcl_Exit(0);
130
                    } else {
131
                        Tcl_Eval(gInterp, "exit");
132
                    }
133
                    break;
134
            }
135
            break;
136
        case kEditMenu:
137
            /*
138
             * This implementation just send keysyms
139
             * the Tk thinks are associated with function keys that
140
             * do Cut, Copy & Paste on a Sun keyboard.
141
             */
142
            GenerateEditEvent(theItem);
143
            break;
144
        default:
145
            TkMacDispatchMenuEvent(theMenu, theItem);
146
            TkMacClearMenubarActive();
147
            break;
148
    }
149
 
150
    /*
151
     * Finally we unhighlight the menu.
152
     */
153
    HiliteMenu(0);
154
} /* TkMacHandleMenuSelect */
155
 
156
/*
157
 *----------------------------------------------------------------------
158
 *
159
 * TkMacInitMenus --
160
 *
161
 *      This procedure initializes the Macintosh menu bar.
162
 *
163
 * Results:
164
 *      None.
165
 *
166
 * Side effects:
167
 *      None.
168
 *
169
 *----------------------------------------------------------------------
170
 */
171
 
172
void
173
TkMacInitMenus(
174
    Tcl_Interp  *interp)
175
{
176
    gInterp = interp;
177
 
178
    /*
179
     * At this point, InitMenus() should have already been called.
180
     */
181
 
182
    if (TkMacUseMenuID(256) != TCL_OK) {
183
        panic("Menu ID 256 is already in use!");
184
    }
185
    tkAppleMenu = NewMenu(256, "\p\024");
186
    if (tkAppleMenu == NULL) {
187
        panic("memory - menus");
188
    }
189
    InsertMenu(tkAppleMenu, 0);
190
    AppendMenu(tkAppleMenu, "\pAbout Tcl & TkÉ");
191
    AppendMenu(tkAppleMenu, "\p(-");
192
    AddResMenu(tkAppleMenu, 'DRVR');
193
 
194
    if (TkMacUseMenuID(kFileMenu) != TCL_OK) {
195
        panic("Menu ID %d is already in use!", kFileMenu);
196
    }
197
    tkFileMenu = NewMenu(kFileMenu, "\pFile");
198
    if (tkFileMenu == NULL) {
199
        panic("memory - menus");
200
    }
201
    InsertMenu(tkFileMenu, 0);
202
    AppendMenu(tkFileMenu, "\pSourceÉ");
203
    AppendMenu(tkFileMenu, "\pClose/W");
204
    AppendMenu(tkFileMenu, "\p(-");
205
    AppendMenu(tkFileMenu, "\pQuit/Q");
206
 
207
    if (TkMacUseMenuID(kEditMenu) != TCL_OK) {
208
        panic("Menu ID %d is already in use!", kEditMenu);
209
    }
210
    tkEditMenu = NewMenu(kEditMenu, "\pEdit");
211
    if (tkEditMenu == NULL) {
212
        panic("memory - menus");
213
    }
214
    InsertMenu(tkEditMenu, 0);
215
    AppendMenu(tkEditMenu, "\pCut/X");
216
    AppendMenu(tkEditMenu, "\pCopy/C");
217
    AppendMenu(tkEditMenu, "\pPaste/V");
218
    AppendMenu(tkEditMenu, "\pClear");
219
    if (TkMacUseMenuID(kHMHelpMenuID) != TCL_OK) {
220
        panic("Help menu ID %s is already in use!", kHMHelpMenuID);
221
    }
222
 
223
    DrawMenuBar();
224
    TkMacSetHelpMenuItemCount();
225
 
226
    return;
227
}
228
 
229
/*
230
 *----------------------------------------------------------------------
231
 *
232
 * GenerateEditEvent --
233
 *
234
 *      Takes an edit menu item and posts the corasponding a virtual
235
 *      event to Tk's event queue.
236
 *
237
 * Results:
238
 *      None.
239
 *
240
 * Side effects:
241
 *      May place events of queue.
242
 *
243
 *----------------------------------------------------------------------
244
 */
245
 
246
static void
247
GenerateEditEvent(
248
    int flag)
249
{
250
    XVirtualEvent event;
251
    Point where;
252
    Tk_Window tkwin;
253
    Window window;
254
 
255
    window = TkMacGetXWindow(FrontWindow());
256
    tkwin = Tk_IdToWindow(tkDisplayList->display, window);
257
    tkwin = (Tk_Window) ((TkWindow *) tkwin)->dispPtr->focusPtr;
258
    if (tkwin == NULL) {
259
        return;
260
    }
261
 
262
    event.type = VirtualEvent;
263
    event.serial = Tk_Display(tkwin)->request;
264
    event.send_event = false;
265
    event.display = Tk_Display(tkwin);
266
    event.event = Tk_WindowId(tkwin);
267
    event.root = XRootWindow(Tk_Display(tkwin), 0);
268
    event.subwindow = None;
269
    event.time = TkpGetMS();
270
 
271
    GetMouse(&where);
272
    tkwin = Tk_TopCoordsToWindow(tkwin, where.h, where.v,
273
            &event.x, &event.y);
274
    LocalToGlobal(&where);
275
    event.x_root = where.h;
276
    event.y_root = where.v;
277
    event.state = TkMacButtonKeyState();
278
    event.same_screen = true;
279
 
280
    switch (flag) {
281
        case EDIT_CUT:
282
            event.name = Tk_GetUid("Cut");
283
            break;
284
 
285
        case EDIT_COPY:
286
            event.name = Tk_GetUid("Copy");
287
            break;
288
 
289
        case EDIT_PASTE:
290
            event.name = Tk_GetUid("Paste");
291
            break;
292
 
293
        case EDIT_CLEAR:
294
            event.name = Tk_GetUid("Clear");
295
            break;
296
    }
297
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
298
}
299
 
300
/*
301
 *----------------------------------------------------------------------
302
 *
303
 * SourceDialog --
304
 *
305
 *      Presents a dialog to the user for selecting a Tcl file.  The
306
 *      selected file will be sourced into the main interpreter.
307
 *
308
 * Results:
309
 *      None.
310
 *
311
 * Side effects:
312
 *      None.
313
 *
314
 *----------------------------------------------------------------------
315
 */
316
 
317
static void
318
SourceDialog()
319
{
320
    StandardFileReply reply;
321
    OSType fileTypes[1];
322
    OSErr err;
323
    int length, result;
324
    Handle path;
325
 
326
    if (gInterp == NULL) {
327
        return;
328
    }
329
 
330
    fileTypes[0] = 'TEXT';
331
    StandardGetFile(NULL, 1, fileTypes, &reply);
332
    if (reply.sfGood == false) {
333
        return;
334
    }
335
 
336
    err = FSpPathFromLocation(&reply.sfFile, &length, &path);
337
    if (err == noErr) {
338
        HLock(path);
339
        result = Tcl_EvalFile(gInterp, *path);
340
        HUnlock(path);
341
        DisposeHandle(path);
342
    }
343
    if (result == TCL_ERROR) {
344
        Tcl_BackgroundError(gInterp);
345
    }
346
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.