1 /* Top level support for Mac interface to GDB, the GNU debugger.
2 Copyright 1994 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Stan Shebs for Cygnus.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include <Resources.h>
26 #include <QuickDraw.h>
34 #include <ToolUtils.h>
45 #include <GestaltEqu.h>
46 #include <PPCToolbox.h>
47 #include <AppleEvents.h>
48 #include <StandardFile.h>
52 #define QD(whatever) (qd.##whatever)
53 #define QDPat(whatever) (&(qd.##whatever))
57 #define QD(whatever) (whatever)
60 #define p2c(pstr,cbuf) \
61 strncpy(cbuf, ((char *) (pstr) + 1), pstr[0]); \
64 #define pascalify(STR) \
65 sprintf(tmpbuf, " %s", STR); \
66 tmpbuf[0] = strlen(STR);
69 #include "call-cmds.h"
74 #include "breakpoint.h"
76 #include "expression.h"
78 #include "terminal.h" /* For job_control. */
88 Rect dragrect
= { -32000, -32000, 32000, 32000 };
93 /* Globals for the console window. */
95 WindowPtr console_window
;
97 ControlHandle console_v_scrollbar
;
99 Rect console_v_scroll_rect
;
101 TEHandle console_text
;
103 Rect console_text_rect
;
108 int eventloopdone
= 0;
118 /* Do the standard Mac environment setup. */
119 InitGraf (&QD (thePort
));
121 FlushEvents (everyEvent
, 0);
128 /* Color Quickdraw is different from Classic QD. */
130 hasColorQD
= se
.hasColorQD
;
134 sizerect
.bottom
= 1000;
135 sizerect
.right
= 1000;
137 sizerect
.bottom
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
138 sizerect
.right
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
141 /* Set up the menus. */
142 menubar
= GetNewMBar (mbMain
);
143 SetMenuBar (menubar
);
144 /* Add the DAs etc as usual. */
145 menu
= GetMHandle (mApple
);
147 AddResMenu (menu
, 'DRVR');
151 /* Create the main window we're going to play in. */
153 console_window
= GetNewCWindow (wConsole
, NULL
, (WindowPtr
) -1L);
155 console_window
= GetNewWindow (wConsole
, NULL
, (WindowPtr
) -1L);
157 if (1) DebugStr("\pnear beginning");
158 SetPort (console_window
);
159 console_text_rect
= console_window
->portRect
;
160 console_text_rect
.bottom
-= sbarwid
- 1;
161 console_text_rect
.right
-= sbarwid
- 1;
162 console_text
= TENew (&console_text_rect
, &console_text_rect
);
163 TESetSelect (0, 32767, console_text
);
164 TEDelete (console_text
);
165 TEInsert ("(gdb)", strlen("(gdb)"), console_text
);
167 console_v_scroll_rect
= console_window
->portRect
;
168 console_v_scroll_rect
.bottom
-= sbarwid
- 1;
169 console_v_scroll_rect
.left
= console_v_scroll_rect
.right
- sbarwid
;
170 console_v_scrollbar
=
171 NewControl (console_window
, &console_v_scroll_rect
,
172 "\p", 1, 0, 0, 0, scrollBarProc
, 0L);
174 ShowWindow (console_window
);
175 SelectWindow (console_window
);
176 /* force_update (console_window); */
184 int eventloopdone
= 0;
194 /* Figure out if the WaitNextEvent Trap is available. */
196 (NGetTrapAddress (0x60, ToolTrap
) != NGetTrapAddress (0x9f, ToolTrap
));
197 /* Pass WNE an empty region the 1st time thru. */
198 cursorRgn
= NewRgn ();
199 /* Go into the main event-handling loop. */
200 while (!eventloopdone
)
202 /* Use WaitNextEvent if it is available, otherwise GetNextEvent. */
205 get_global_mouse (&mouse
);
206 adjust_cursor (mouse
, cursorRgn
);
207 gotevent
= WaitNextEvent (everyEvent
, &event
, 0L, cursorRgn
);
212 gotevent
= GetNextEvent (everyEvent
, &event
);
214 /* First decide if the event is for a dialog or is just any old event. */
215 if (FrontWindow () != nil
&& IsDialogEvent (&event
))
220 /* Handle all the modeless dialogs here. */
221 if (DialogSelect (&event
, &dialog
, &itemhit
))
227 /* Make sure we have the right cursor before handling the event. */
228 adjust_cursor (event
.where
, cursorRgn
);
234 get_global_mouse (mouse
)
239 OSEventAvail (0, &evt
);
243 adjust_cursor (mouse
, region
)
249 /* Decipher an event, maybe do something with it. */
254 short part
, err
, rslt
= 0;
263 /* See if the click happened in a special part of the screen. */
264 part
= FindWindow (evt
->where
, &win
);
269 do_menu_command (MenuSelect (evt
->where
));
272 SystemClick (evt
, win
);
275 if (win
!= FrontWindow ())
277 /* Bring the clicked-on window to the front. */
279 /* Fix the menu to match the new front window. */
281 /* We always want to discard the event now, since clicks in a
282 windows are often irreversible actions. */
284 /* Mouse clicks in the front window do something useful. */
285 do_mouse_down (win
, evt
);
288 /* Standard drag behavior, no tricks necessary. */
289 DragWindow (win
, evt
->where
, &dragrect
);
292 grow_window (win
, evt
->where
);
296 zoom_window (win
, evt
->where
, part
);
305 key
= evt
->message
& charCodeMask
;
306 /* Check for menukey equivalents. */
307 if (evt
->modifiers
& cmdKey
)
309 if (evt
->what
== keyDown
)
312 do_menu_command (MenuKey (key
));
317 if (evt
->what
== keyDown
)
319 /* Random keypress, interpret it. */
320 do_keyboard_command (key
);
325 activate_window ((WindowPtr
) evt
->message
, evt
->modifiers
& activeFlag
);
328 update_window ((WindowPtr
) evt
->message
);
331 /* Call DIBadMount in response to a diskEvt, so that the user can format
332 a floppy. (from DTS Sample) */
333 if (HiWord (evt
->message
) != noErr
)
335 SetPt (&pnt
, 50, 50);
336 err
= DIBadMount (pnt
, evt
->message
);
340 /* Grab only a single byte. */
341 switch ((evt
->message
>> 24) & 0xFF)
346 inbackground
= !(evt
->message
& 1);
347 activate_window (FrontWindow (), !inbackground
);
351 case kHighLevelEvent
:
352 AEProcessAppleEvent (evt
);
363 grow_window (win
, where
)
371 winsize
= GrowWindow (win
, where
, &sizerect
);
376 EraseRect (&win
->portRect
);
377 h
= LoWord (winsize
);
378 v
= HiWord (winsize
);
379 SizeWindow (win
, h
, v
, 1);
380 if (win
== console_window
)
382 MoveControl(console_v_scrollbar
, h
- sbarwid
, 0);
383 SizeControl(console_v_scrollbar
, sbarwid
+ 1, v
- sbarwid
+ 1);
385 InvalRect (&win
->portRect
);
390 zoom_window (win
, where
, part
)
402 do_mouse_down (win
, event
)
408 ControlHandle control
;
410 if (1 /*is_app_window(win)*/)
413 mouse
= event
->where
;
414 GlobalToLocal (&mouse
);
415 part
= FindControl(mouse
, win
, &control
);
416 if (control
== console_v_scrollbar
)
422 TEClick (mouse
, 0, console_text
);
427 activate_window (win
, activate
)
431 if (win
== nil
) return;
432 /* It's convenient to make the activated window also be the
436 /* Activate the console window's scrollbar. */
437 if (win
== console_window
)
438 HiliteControl (console_v_scrollbar
, (activate
? 0 : 255));
444 int controls
= 1, growbox
= 0;
447 /* Set the updating window to be the current grafport. */
450 /* recalc_depths(); */
452 if (win
== console_window
)
459 UpdateControls (win
, win
->visRgn
);
470 do_menu_command (which
)
473 short menuid
, menuitem
;
482 menuid
= HiWord (which
);
483 menuitem
= LoWord (which
);
490 /* Alert(aAbout, nil); */
493 GetItem (GetMHandle (mApple
), menuitem
, daname
);
494 daRefNum
= OpenDeskAcc (daname
);
506 /* handledbyda = SystemEdit(menuitem-1); */
523 char commandbuf
[1000];
525 do_keyboard_command (key
)
528 int startpos
, endpos
, i
;
529 char buf
[10], *text_str
, *command
;
532 if (key
== '\015' || key
== '\003')
534 /* (should) Interpret the line as a command. */
535 text
= TEGetText (console_text
);
536 HLock ((Handle
) text
);
537 startpos
= (*console_text
)->selStart
;
538 endpos
= (*console_text
)->selEnd
;
539 if (startpos
!= endpos
)
541 strncpy (commandbuf
+ 1, *text
+ startpos
, endpos
- startpos
);
542 commandbuf
[1 + endpos
- startpos
] = 0;
543 command
= commandbuf
+ 1;
547 for (i
= startpos
; i
> 0; --i
)
549 strncpy (buf
, *text
+ i
, 5);
551 if (strncmp (buf
, "(gdb)") == 0)
556 strncpy (commandbuf
+ 1, *text
+ i
+ 5, startpos
- i
);
557 commandbuf
[1 + startpos
- i
] = '\0';
562 commandbuf
[1] = '\0';
564 command
= commandbuf
+ 1;
566 HUnlock ((Handle
) text
);
567 commandbuf
[0] = strlen(command
);
568 DebugStr(commandbuf
);
570 /* Insert a newline and redraw before doing the command. */
572 TEInsert (buf
, 1, console_text
);
573 TESetSelect (100000, 100000, console_text
);
576 execute_command (commandbuf
, 0);
577 bpstat_do_actions (&stop_bpstat
);
579 else if (0 /* editing chars... */)
584 /* A self-inserting character. */
586 TEInsert (buf
, 1, console_text
);
587 TESetSelect (100000, 100000, console_text
);
597 SetPort (console_window
);
598 TEUpdate (&(console_window
->portRect
), console_text
);
600 /* adjust_help_scrollbar(); */
603 /* Cause an update of a window's entire contents. */
610 if (win
== nil
) return;
613 EraseRect (&win
->portRect
);
614 InvalRect (&win
->portRect
);
618 adjust_console_scrollbars ()
620 int lines
, newmax
, value
;
622 lines
= (*console_text
)->nLines
;
623 newmax
= lines
- (((*console_text
)->viewRect
.bottom
- (*console_text
)->viewRect
.top
)
624 / (*console_text
)->lineHeight
);
625 if (newmax
< 0) newmax
= 0;
626 SetCtlMax(console_v_scrollbar
, newmax
);
627 value
= ((*console_text
)->viewRect
.top
- (*console_text
)->destRect
.top
)
628 / (*console_text
)->lineHeight
;
629 SetCtlValue(console_v_scrollbar
, value
);