1 /* $Id: macevlog.c,v 1.7 2003/04/12 21:06:34 ben Exp $ */
3 * Copyright (c) 2003 Ben Harris
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <MacWindows.h>
31 #include <Quickdraw.h>
33 #include <ToolUtils.h>
43 static void mac_draweventloggrowicon(Session
*s
);
44 static void mac_adjusteventlogscrollbar(Session
*s
);
45 static void mac_clickeventlog(WindowPtr
, EventRecord
*);
46 static void mac_activateeventlog(WindowPtr
, EventRecord
*);
47 static void mac_groweventlog(WindowPtr
, EventRecord
*);
48 static void mac_updateeventlog(WindowPtr
);
49 static void mac_closeeventlog(WindowPtr
);
51 static void mac_createeventlog(Session
*s
)
54 ListBounds bounds
= { 0, 0, 0, 1 }; /* 1 column, 0 rows */
55 Point csize
= { 0, 0 };
60 s
->eventlog_window
= GetNewWindow(wEventLog
, NULL
, (WindowPtr
)-1);
62 memset(wi
, 0, sizeof(*wi
));
64 wi
->wtype
= wEventLog
;
65 wi
->click
= &mac_clickeventlog
;
66 wi
->activate
= &mac_activateeventlog
;
67 wi
->grow
= &mac_groweventlog
;
68 wi
->update
= &mac_updateeventlog
;
69 wi
->close
= &mac_closeeventlog
;
70 SetWRefCon(s
->eventlog_window
, (long)wi
);
72 SetPort((GrafPtr
)GetWindowPort(s
->eventlog_window
));
73 fondsize
= GetScriptVariable(smRoman
, smScriptSmallFondSize
);
74 TextFont(HiWord(fondsize
));
75 TextSize(LoWord(fondsize
));
77 #if TARGET_API_MAC_CARBON
78 GetPortBounds(GetWindowPort(s
->eventlog_window
), &view
);
80 view
= s
->eventlog_window
->portRect
;
82 view
.right
-= 15; /* Scrollbar */
83 s
->eventlog
= LNew(&view
, &bounds
, csize
, 0, s
->eventlog_window
,
84 TRUE
, TRUE
, FALSE
, TRUE
);
85 mac_adjusteventlogscrollbar(s
);
86 #if TARGET_API_MAC_CARBON
87 SetListSelectionFlags(s
->eventlog
, lExtendDrag
| lNoDisjoint
| lNoExtend
);
89 (*s
->eventlog
)->selFlags
= lExtendDrag
| lNoDisjoint
| lNoExtend
;
93 void mac_freeeventlog(Session
*s
)
96 if (s
->eventlog
!= NULL
)
97 LDispose(s
->eventlog
);
98 if (s
->eventlog_window
!= NULL
) {
99 sfree((WinInfo
*)GetWRefCon(s
->eventlog_window
));
100 DisposeWindow(s
->eventlog_window
);
104 void logevent(void *frontend
, char *str
)
106 Session
*s
= frontend
;
107 ListBounds bounds
, visible
;
108 Cell cell
= { 0, 0 };
110 if (s
->eventlog
== NULL
)
111 mac_createeventlog(s
);
112 if (s
->eventlog
== NULL
)
115 #if TARGET_API_MAC_CARBON
116 GetListDataBounds(s
->eventlog
, &bounds
);
117 GetListVisibleCells(s
->eventlog
, &visible
);
119 bounds
= (*s
->eventlog
)->dataBounds
;
120 visible
= (*s
->eventlog
)->visible
;
123 cell
.v
= bounds
.bottom
;
124 LAddRow(1, cell
.v
, s
->eventlog
);
125 LSetCell(str
, strlen(str
), cell
, s
->eventlog
);
126 /* ">=" and "2" because there can be a blank cell below the last one. */
127 if (visible
.bottom
>= bounds
.bottom
)
128 LScroll(0, 2, s
->eventlog
);
131 static void mac_draweventloggrowicon(Session
*s
)
136 SetPort((GrafPtr
)GetWindowPort(s
->eventlog_window
));
138 * Stop DrawGrowIcon giving us space for a horizontal scrollbar
139 * See Tech Note TB575 for details.
141 #if TARGET_API_MAC_CARBON
142 GetPortBounds(GetWindowPort(s
->eventlog_window
), &clip
);
144 clip
= s
->eventlog_window
->portRect
;
146 clip
.left
= clip
.right
- 15;
150 DrawGrowIcon(s
->eventlog_window
);
156 * For some reason, LNew doesn't seem to respect the hasGrow
157 * parameter, so we hammer the scrollbar into shape ourselves.
159 static void mac_adjusteventlogscrollbar(Session
*s
)
161 #if TARGET_API_MAC_CARBON
164 GetPortBounds(GetWindowPort(s
->eventlog_window
), &winrect
);
165 SizeControl(GetListVerticalScrollBar(s
->eventlog
),
166 16, winrect
.bottom
- 13);
168 SizeControl((*s
->eventlog
)->vScroll
,
169 16, s
->eventlog_window
->portRect
.bottom
- 13);
173 void mac_clickeventlog(WindowPtr window
, EventRecord
*event
)
175 Session
*s
= mac_windowsession(window
);
180 SetPort((GrafPtr
)GetWindowPort(window
));
181 mouse
= event
->where
;
182 GlobalToLocal(&mouse
);
183 LClick(mouse
, event
->modifiers
, s
->eventlog
);
187 static void mac_groweventlog(WindowPtr window
, EventRecord
*event
)
189 Session
*s
= mac_windowsession(window
);
192 #if TARGET_API_MAC_CARBON
199 SetRect(&limits
, 15, 0, SHRT_MAX
, SHRT_MAX
);
200 grow_result
= GrowWindow(window
, event
->where
, &limits
);
201 if (grow_result
== 0) return;
202 SizeWindow(window
, LoWord(grow_result
), HiWord(grow_result
), TRUE
);
203 LSize(LoWord(grow_result
) - 15, HiWord(grow_result
), s
->eventlog
);
204 mac_adjusteventlogscrollbar(s
);
205 /* We would use SetListCellSize in Carbon, but it's missing. */
206 (*s
->eventlog
)->cellSize
.h
= LoWord(grow_result
) - 15;
207 #if TARGET_API_MAC_CARBON
208 cellsize
.h
= LoWord(grow_result
) - 15;
209 GetListViewBounds(s
->eventlog
, &rect
);
210 InvalWindowRect(window
, &rect
);
214 InvalRect(&(*s
->eventlog
)->rView
);
219 static void mac_activateeventlog(WindowPtr window
, EventRecord
*event
)
221 Session
*s
= mac_windowsession(window
);
222 int active
= (event
->modifiers
& activeFlag
) != 0;
224 LActivate(active
, s
->eventlog
);
225 mac_draweventloggrowicon(s
);
228 static void mac_updateeventlog(WindowPtr window
)
230 Session
*s
= mac_windowsession(window
);
231 #if TARGET_API_MAC_CARBON
235 SetPort((GrafPtr
)GetWindowPort(window
));
237 #if TARGET_API_MAC_CARBON
239 GetPortVisibleRegion(GetWindowPort(window
), visrgn
);
240 LUpdate(visrgn
, s
->eventlog
);
243 LUpdate(window
->visRgn
, s
->eventlog
);
245 mac_draweventloggrowicon(s
);
249 static void mac_closeeventlog(WindowPtr window
)
255 void mac_showeventlog(Session
*s
)
258 SelectWindow(s
->eventlog_window
);
259 ShowWindow(s
->eventlog_window
);
264 * c-file-style: "simon"