• R/O
  • SSH
  • HTTPS

marathon: コミット


コミットメタ情報

リビジョン522 (tree)
日時2012-06-02 13:41:32
作者ookawa_mi

ログメッセージ

AlephOne 1.0.2対応
改行コード修正

変更サマリ

差分

--- marathon/trunk/Source_Files/CSeries/cstypes.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/cstypes.h (revision 522)
@@ -1,113 +1,113 @@
1-/* cstypes.h
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-
22-#ifndef _CSERIES_TYPES_
23-#define _CSERIES_TYPES_
24-
25-#include <limits.h>
26-#ifdef HAVE_CONFIG_H // pick up HAVE_OPENGL
27-#include "config.h"
28-#endif
29-
30-// IR note: consts in headers are slow and eat TOC space.
31-//const int NONE = -1;
32-enum {
33- NONE = -1,
34- UNONE = 65535
35-};
36-
37-// Integer types with specific bit size
38-#if defined(mac)
39-#if defined(EXPLICIT_CARBON_HEADER)
40- #include <Carbon/Carbon.h>
41-#endif
42-
43-typedef SInt8 int8;
44-typedef UInt8 uint8;
45-typedef SInt16 int16;
46-typedef UInt16 uint16;
47-typedef SInt32 int32;
48-typedef UInt32 uint32;
49-typedef uint32 TimeType;
50-
51-#elif defined(__BEOS__)
52-
53-#include <support/SupportDefs.h>
54-typedef time_t TimeType;
55-
56-#elif defined(SDL)
57-
58-#include <SDL_types.h>
59-#include <time.h> // for time_t
60-typedef Uint8 uint8;
61-typedef Sint8 int8;
62-typedef Uint16 uint16;
63-typedef Sint16 int16;
64-typedef Uint32 uint32;
65-typedef Sint32 int32;
66-typedef time_t TimeType;
67-
68-#endif
69-
70-// Minimum and maximum values for these types
71-#ifndef INT16_MAX
72-#define INT16_MAX 32767
73-#endif
74-#ifndef UINT16_MAX
75-#define UINT16_MAX 65535
76-#endif
77-#ifndef INT16_MIN
78-#define INT16_MIN (-INT16_MAX-1)
79-#endif
80-#ifndef INT32_MAX
81-#define INT32_MAX 2147483647
82-#endif
83-#ifndef INT32_MIN
84-#define INT32_MIN (-INT32_MAX-1)
85-#endif
86-
87-// Fixed point (16.16) type
88-// LP: changed to _fixed to get around MSVC namespace conflict
89-typedef int32 _fixed;
90-
91-#define FIXED_FRACTIONAL_BITS 16
92-#define INTEGER_TO_FIXED(i) ((_fixed)(i)<<FIXED_FRACTIONAL_BITS)
93-#define FIXED_INTEGERAL_PART(f) ((f)>>FIXED_FRACTIONAL_BITS)
94-
95-#define FIXED_ONE (1L<<FIXED_FRACTIONAL_BITS)
96-#define FIXED_ONE_HALF (1L<<(FIXED_FRACTIONAL_BITS-1))
97-
98-// Binary powers
99-const int MEG = 0x100000;
100-const int KILO = 0x400L;
101-
102-// Construct four-character-code
103-#define FOUR_CHARS_TO_INT(a,b,c,d) (((uint32)(a) << 24) | ((uint32)(b) << 16) | ((uint32)(c) << 8) | (uint32)(d))
104-
105-// Hmmm, this should be removed one day...
106-typedef uint8 byte;
107-
108-// Make it compile on systems without OpenGL
109-#ifndef HAVE_OPENGL
110-#define GLfloat float
111-#endif
112-
113-#endif
1+/* cstypes.h
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+
22+#ifndef _CSERIES_TYPES_
23+#define _CSERIES_TYPES_
24+
25+#include <limits.h>
26+#ifdef HAVE_CONFIG_H // pick up HAVE_OPENGL
27+#include "config.h"
28+#endif
29+
30+// IR note: consts in headers are slow and eat TOC space.
31+//const int NONE = -1;
32+enum {
33+ NONE = -1,
34+ UNONE = 65535
35+};
36+
37+// Integer types with specific bit size
38+#if defined(mac)
39+#if defined(EXPLICIT_CARBON_HEADER)
40+ #include <Carbon/Carbon.h>
41+#endif
42+
43+typedef SInt8 int8;
44+typedef UInt8 uint8;
45+typedef SInt16 int16;
46+typedef UInt16 uint16;
47+typedef SInt32 int32;
48+typedef UInt32 uint32;
49+typedef uint32 TimeType;
50+
51+#elif defined(__BEOS__)
52+
53+#include <support/SupportDefs.h>
54+typedef time_t TimeType;
55+
56+#elif defined(SDL)
57+
58+#include <SDL_types.h>
59+#include <time.h> // for time_t
60+typedef Uint8 uint8;
61+typedef Sint8 int8;
62+typedef Uint16 uint16;
63+typedef Sint16 int16;
64+typedef Uint32 uint32;
65+typedef Sint32 int32;
66+typedef time_t TimeType;
67+
68+#endif
69+
70+// Minimum and maximum values for these types
71+#ifndef INT16_MAX
72+#define INT16_MAX 32767
73+#endif
74+#ifndef UINT16_MAX
75+#define UINT16_MAX 65535
76+#endif
77+#ifndef INT16_MIN
78+#define INT16_MIN (-INT16_MAX-1)
79+#endif
80+#ifndef INT32_MAX
81+#define INT32_MAX 2147483647
82+#endif
83+#ifndef INT32_MIN
84+#define INT32_MIN (-INT32_MAX-1)
85+#endif
86+
87+// Fixed point (16.16) type
88+// LP: changed to _fixed to get around MSVC namespace conflict
89+typedef int32 _fixed;
90+
91+#define FIXED_FRACTIONAL_BITS 16
92+#define INTEGER_TO_FIXED(i) ((_fixed)(i)<<FIXED_FRACTIONAL_BITS)
93+#define FIXED_INTEGERAL_PART(f) ((f)>>FIXED_FRACTIONAL_BITS)
94+
95+#define FIXED_ONE (1L<<FIXED_FRACTIONAL_BITS)
96+#define FIXED_ONE_HALF (1L<<(FIXED_FRACTIONAL_BITS-1))
97+
98+// Binary powers
99+const int MEG = 0x100000;
100+const int KILO = 0x400L;
101+
102+// Construct four-character-code
103+#define FOUR_CHARS_TO_INT(a,b,c,d) (((uint32)(a) << 24) | ((uint32)(b) << 16) | ((uint32)(c) << 8) | (uint32)(d))
104+
105+// Hmmm, this should be removed one day...
106+typedef uint8 byte;
107+
108+// Make it compile on systems without OpenGL
109+#ifndef HAVE_OPENGL
110+#define GLfloat float
111+#endif
112+
113+#endif
--- marathon/trunk/Source_Files/CSeries/csfiles_beos.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/csfiles_beos.cpp (revision 522)
@@ -1,201 +1,201 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-/*
22- * csfiles_beos.cpp - Some BeOS-specific functions that didn't fit elsewhere
23- *
24- * Written in 2000 by Christian Bauer
25- */
26-
27-#include <SDL_rwops.h>
28-#include <SDL_error.h>
29-
30-#include <AppKit.h>
31-#include <StorageKit.h>
32-#include <string>
33-#include <unistd.h>
34-#include <fcntl.h>
35-#include <fs_attr.h>
36-
37-
38-/*
39- * Find application and preferences directories
40- */
41-
42-string get_application_directory(void)
43-{
44- app_info info;
45- be_app->GetAppInfo(&info);
46- BEntry entry(&info.ref);
47- BPath path(&entry), dir;
48- path.GetParent(&dir);
49- return dir.Path();
50-}
51-
52-string get_preferences_directory(void)
53-{
54- BPath prefs_dir;
55- find_directory(B_USER_SETTINGS_DIRECTORY, &prefs_dir, true);
56- prefs_dir.Append("Aleph One");
57- return prefs_dir.Path();
58-}
59-
60-
61-/*
62- * Handling of resource forks in BFS attributes. The BeOS HFS implementation
63- * makes the resource forks of files available as a file attribute with the
64- * name "MACOS:RFORK". We handle these attributes here to make it possible
65- * to copy Marathon data files from Mac CD-ROMs without any need for file
66- * conversion.
67- */
68-
69-#define ATTR_NAME "MACOS:RFORK"
70-
71-bool has_rfork_attribute(const char *file)
72-{
73- int fd = open(file, O_RDONLY);
74- if (fd < 0)
75- return false;
76-
77- struct attr_info info;
78- bool result = (fs_stat_attr(fd, ATTR_NAME, &info) == 0);
79-
80- close(fd);
81- return result;
82-}
83-
84-struct rfork_data {
85- int fd; // fd of file
86- off_t current; // current position in attribute
87- off_t size; // size of attribute
88-};
89-
90-static int rfork_seek(SDL_RWops *context, int offset, int whence)
91-{
92- rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
93-
94- off_t newpos;
95- switch (whence) {
96- case SEEK_SET:
97- newpos = offset;
98- break;
99- case SEEK_CUR:
100- newpos = d->current + offset;
101- break;
102- case SEEK_END:
103- newpos = d->size + offset;
104- break;
105- default:
106- SDL_SetError("Unknown value for 'whence'");
107- return -1;
108- }
109-
110- if (newpos < 0 || newpos > d->size) {
111- SDL_Error(SDL_EFSEEK);
112- return -1;
113- }
114-
115- d->current = newpos;
116- return newpos;
117-}
118-
119-static int rfork_read(SDL_RWops *context, void *ptr, int size, int maxnum)
120-{
121- rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
122-
123- int num = maxnum;
124- if (d->current + (num*size) > d->size)
125- num = (d->size - d->current) / size;
126-
127- ssize_t actual = fs_read_attr(d->fd, ATTR_NAME, B_RAW_TYPE, d->current, ptr, num * size);
128- if (actual < 0)
129- return actual;
130- else {
131- d->current += actual;
132- return actual / size;
133- }
134-}
135-
136-static int rfork_write(SDL_RWops *context, const void *ptr, int size, int maxnum)
137-{
138- rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
139-
140- int num = maxnum;
141- if (d->current + (num*size) > d->size)
142- num = (d->size - d->current) / size;
143-
144- ssize_t actual = fs_write_attr(d->fd, ATTR_NAME, B_RAW_TYPE, d->current, ptr, num * size);
145- if (actual < 0)
146- return actual;
147- else {
148- d->current += actual;
149- return actual / size;
150- }
151-}
152-
153-static int rfork_close(SDL_RWops *context)
154-{
155- if (context) {
156- rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
157- close(d->fd);
158- free(d);
159- free(context);
160- }
161- return 0;
162-}
163-
164-SDL_RWops *sdl_rw_from_rfork(const char *file, bool writable)
165-{
166- SDL_RWops *rwops = NULL;
167-
168- int fd = open(file, writable ? O_RDWR : O_RDONLY);
169- if (fd < 0) {
170- SDL_SetError("Couldn't open %s", file);
171- return NULL;
172- } else {
173- struct attr_info info;
174- fs_stat_attr(fd, ATTR_NAME, &info);
175-
176- rwops = SDL_AllocRW();
177- if (rwops == NULL) {
178- close(fd);
179- return NULL;
180- }
181-
182- rfork_data *d = (rfork_data *)malloc(sizeof(struct rfork_data));
183- if (d == NULL) {
184- free(rwops);
185- close(fd);
186- return NULL;
187- }
188-
189- d->fd = fd;
190- d->current = 0;
191- d->size = info.size;
192-
193- rwops->seek = rfork_seek;
194- rwops->read = rfork_read;
195- rwops->write = rfork_write;
196- rwops->close = rfork_close;
197- rwops->hidden.unknown.data1 = d;
198-
199- return rwops;
200- }
201-}
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+/*
22+ * csfiles_beos.cpp - Some BeOS-specific functions that didn't fit elsewhere
23+ *
24+ * Written in 2000 by Christian Bauer
25+ */
26+
27+#include <SDL_rwops.h>
28+#include <SDL_error.h>
29+
30+#include <AppKit.h>
31+#include <StorageKit.h>
32+#include <string>
33+#include <unistd.h>
34+#include <fcntl.h>
35+#include <fs_attr.h>
36+
37+
38+/*
39+ * Find application and preferences directories
40+ */
41+
42+string get_application_directory(void)
43+{
44+ app_info info;
45+ be_app->GetAppInfo(&info);
46+ BEntry entry(&info.ref);
47+ BPath path(&entry), dir;
48+ path.GetParent(&dir);
49+ return dir.Path();
50+}
51+
52+string get_preferences_directory(void)
53+{
54+ BPath prefs_dir;
55+ find_directory(B_USER_SETTINGS_DIRECTORY, &prefs_dir, true);
56+ prefs_dir.Append("Aleph One");
57+ return prefs_dir.Path();
58+}
59+
60+
61+/*
62+ * Handling of resource forks in BFS attributes. The BeOS HFS implementation
63+ * makes the resource forks of files available as a file attribute with the
64+ * name "MACOS:RFORK". We handle these attributes here to make it possible
65+ * to copy Marathon data files from Mac CD-ROMs without any need for file
66+ * conversion.
67+ */
68+
69+#define ATTR_NAME "MACOS:RFORK"
70+
71+bool has_rfork_attribute(const char *file)
72+{
73+ int fd = open(file, O_RDONLY);
74+ if (fd < 0)
75+ return false;
76+
77+ struct attr_info info;
78+ bool result = (fs_stat_attr(fd, ATTR_NAME, &info) == 0);
79+
80+ close(fd);
81+ return result;
82+}
83+
84+struct rfork_data {
85+ int fd; // fd of file
86+ off_t current; // current position in attribute
87+ off_t size; // size of attribute
88+};
89+
90+static int rfork_seek(SDL_RWops *context, int offset, int whence)
91+{
92+ rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
93+
94+ off_t newpos;
95+ switch (whence) {
96+ case SEEK_SET:
97+ newpos = offset;
98+ break;
99+ case SEEK_CUR:
100+ newpos = d->current + offset;
101+ break;
102+ case SEEK_END:
103+ newpos = d->size + offset;
104+ break;
105+ default:
106+ SDL_SetError("Unknown value for 'whence'");
107+ return -1;
108+ }
109+
110+ if (newpos < 0 || newpos > d->size) {
111+ SDL_Error(SDL_EFSEEK);
112+ return -1;
113+ }
114+
115+ d->current = newpos;
116+ return newpos;
117+}
118+
119+static int rfork_read(SDL_RWops *context, void *ptr, int size, int maxnum)
120+{
121+ rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
122+
123+ int num = maxnum;
124+ if (d->current + (num*size) > d->size)
125+ num = (d->size - d->current) / size;
126+
127+ ssize_t actual = fs_read_attr(d->fd, ATTR_NAME, B_RAW_TYPE, d->current, ptr, num * size);
128+ if (actual < 0)
129+ return actual;
130+ else {
131+ d->current += actual;
132+ return actual / size;
133+ }
134+}
135+
136+static int rfork_write(SDL_RWops *context, const void *ptr, int size, int maxnum)
137+{
138+ rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
139+
140+ int num = maxnum;
141+ if (d->current + (num*size) > d->size)
142+ num = (d->size - d->current) / size;
143+
144+ ssize_t actual = fs_write_attr(d->fd, ATTR_NAME, B_RAW_TYPE, d->current, ptr, num * size);
145+ if (actual < 0)
146+ return actual;
147+ else {
148+ d->current += actual;
149+ return actual / size;
150+ }
151+}
152+
153+static int rfork_close(SDL_RWops *context)
154+{
155+ if (context) {
156+ rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
157+ close(d->fd);
158+ free(d);
159+ free(context);
160+ }
161+ return 0;
162+}
163+
164+SDL_RWops *sdl_rw_from_rfork(const char *file, bool writable)
165+{
166+ SDL_RWops *rwops = NULL;
167+
168+ int fd = open(file, writable ? O_RDWR : O_RDONLY);
169+ if (fd < 0) {
170+ SDL_SetError("Couldn't open %s", file);
171+ return NULL;
172+ } else {
173+ struct attr_info info;
174+ fs_stat_attr(fd, ATTR_NAME, &info);
175+
176+ rwops = SDL_AllocRW();
177+ if (rwops == NULL) {
178+ close(fd);
179+ return NULL;
180+ }
181+
182+ rfork_data *d = (rfork_data *)malloc(sizeof(struct rfork_data));
183+ if (d == NULL) {
184+ free(rwops);
185+ close(fd);
186+ return NULL;
187+ }
188+
189+ d->fd = fd;
190+ d->current = 0;
191+ d->size = info.size;
192+
193+ rwops->seek = rfork_seek;
194+ rwops->read = rfork_read;
195+ rwops->write = rfork_write;
196+ rwops->close = rfork_close;
197+ rwops->hidden.unknown.data1 = d;
198+
199+ return rwops;
200+ }
201+}
--- marathon/trunk/Source_Files/CSeries/readout_data.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/readout_data.h (revision 522)
@@ -1,54 +1,54 @@
1-#ifndef __READOUT_DATA_H
2-#define __READOUT_DATA_H
3-
4-/*
5-USAGE_TIMERS.H
6-Sunday, September 30, 2001
7-
8-Sept 30, 2001 (Ian Rickard):
9- Created so I can add stuff without recompiling the whole app. (shell.h is in my precomp header)
10-*/
11-
12-#include "timer.h"
13-
14-struct time_usage_stats
15-{
16- Timer total;
17- Timer totalUsed;
18- Timer world, worldAI, worldCollision;
19- Timer vis, visTree, visFlat;
20- Timer render, renderCalc, renderObj, renderClip, renderDraw;
21- Timer blit;
22-};
23-
24-struct prerender_stats
25-{
26- int totalNodes, totalWindows, sortedNodes, combinedWindows;
27- int objects, objectWindows;
28-};
29-
30-struct render_stats
31-{
32- int vertical, verticalWindows, horizontal, horizontalWindows, sprites, spriteWindows;
33- int surfacePixels, spritePixels;
34- int surfaces, polys;
35-};
36-
37-struct OGL_TexturesStats {
38- int inUse;
39- int binds, totalBind, minBind, maxBind;
40- int longNormalSetups, longGlowSetups;
41- int totalAge;
42- OGL_TexturesStats() {
43- inUse=binds=totalBind=0;
44- minBind=500000;
45- maxBind=longNormalSetups=longGlowSetups=totalAge=0;
46- }
47-};
48-
49-extern prerender_stats gPrerenderStats;
50-extern render_stats gRenderStats;
51-extern time_usage_stats gUsageTimers;
52-extern OGL_TexturesStats gGLTxStats;
53-
54-#endif
1+#ifndef __READOUT_DATA_H
2+#define __READOUT_DATA_H
3+
4+/*
5+USAGE_TIMERS.H
6+Sunday, September 30, 2001
7+
8+Sept 30, 2001 (Ian Rickard):
9+ Created so I can add stuff without recompiling the whole app. (shell.h is in my precomp header)
10+*/
11+
12+#include "timer.h"
13+
14+struct time_usage_stats
15+{
16+ Timer total;
17+ Timer totalUsed;
18+ Timer world, worldAI, worldCollision;
19+ Timer vis, visTree, visFlat;
20+ Timer render, renderCalc, renderObj, renderClip, renderDraw;
21+ Timer blit;
22+};
23+
24+struct prerender_stats
25+{
26+ int totalNodes, totalWindows, sortedNodes, combinedWindows;
27+ int objects, objectWindows;
28+};
29+
30+struct render_stats
31+{
32+ int vertical, verticalWindows, horizontal, horizontalWindows, sprites, spriteWindows;
33+ int surfacePixels, spritePixels;
34+ int surfaces, polys;
35+};
36+
37+struct OGL_TexturesStats {
38+ int inUse;
39+ int binds, totalBind, minBind, maxBind;
40+ int longNormalSetups, longGlowSetups;
41+ int totalAge;
42+ OGL_TexturesStats() {
43+ inUse=binds=totalBind=0;
44+ minBind=500000;
45+ maxBind=longNormalSetups=longGlowSetups=totalAge=0;
46+ }
47+};
48+
49+extern prerender_stats gPrerenderStats;
50+extern render_stats gRenderStats;
51+extern time_usage_stats gUsageTimers;
52+extern OGL_TexturesStats gGLTxStats;
53+
54+#endif
--- marathon/trunk/Source_Files/CSeries/cseries.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/cseries.h (revision 522)
@@ -1,139 +1,139 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-// Loren Petrich: the author(s) of the "cseries" files is not given, but is probably
22-// either Bo Lindbergh, Mihai Parparita, or both, given their efforts in getting the
23-// code working initially.
24-// AS: It was almost certainly Bo Lindbergh
25-#ifndef _CSERIES
26-#define _CSERIES
27-
28-#ifdef HAVE_CONFIG_H
29-#include "config.h"
30-#else
31-#define VERSION "unknown version"
32-#endif
33-
34-#include <SDL.h>
35-#include <SDL_byteorder.h>
36-#include <time.h>
37-#include <string>
38-
39-#define DEBUG
40-
41-#ifndef __MVCPP__
42-
43-// mwcc doesn't accept "using namespace std;" otherwise
44-namespace std {};
45-
46-#elif __MVCPP__
47-
48-using namespace std; // Visual C++ doesn't like that other way of using the namespace.
49-#if _MSC_VER < 1300
50-#define for if(false) {} else for // solves a bug in MSVC prior to MSVC7 for the "redeclared" initializers used in for loops.
51-#endif
52-
53-//#define VERSION "1.0"
54-
55-#endif
56-
57-/*
58- * Endianess definitions
59- */
60-
61-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
62-#define ALEPHONE_LITTLE_ENDIAN 1
63-#else
64-#undef ALEPHONE_LITTLE_ENDIAN
65-#endif
66-
67-
68-/*
69- * Data types with specific bit width
70- */
71-
72-#include "cstypes.h"
73-
74-/*
75- * Emulation of MacOS data types and definitions
76- */
77-#if !defined(SDL_RFORK_HACK)// && !defined(TARGET_API_MAC_CARBON)
78-
79-#if defined(__APPLE__) && defined(__MACH__)
80-// if we're on the right platform, we can use the real thing (and get headers for functions we might want to use)
81-#include <CoreFoundation/CoreFoundation.h>
82-#elif !defined(TARGET_API_MAC_CARBON)
83-typedef int OSErr;
84-typedef unsigned char Str255[256];
85-
86-struct Rect {
87- int16 top, left;
88- int16 bottom, right;
89-};
90-
91-const int noErr = 0;
92-#endif
93-
94-struct RGBColor {
95- uint16 red, green, blue;
96-};
97-
98-const int kFontIDMonaco = 4;
99-const int kFontIDCourier = 22;
100-
101-#else
102-# if !defined(TARGET_API_MAC_CARBON)
103-# define DEBUGASSERTMSG
104-# endif
105-# ifdef DEBUG
106-# define WAS_DEBUG
107-//AS: this is ugly...
108-
109-# undef DEBUG
110-# endif
111-# if !defined(TARGET_API_MAC_CARBON)
112-# define dialog CHEESEOFDEATH
113-# define DialogPtr mDialogPtr
114-# include <MacTypes.h>
115-# include <Quickdraw.h>
116-# undef dialog
117-# undef DialogPtr
118-# endif
119-# ifdef WAS_DEBUG
120-# define DEBUG
121-# endif
122-#endif
123-
124-/*
125- * Include CSeries headers
126- */
127-
128-#include "cstypes.h"
129-#include "csmacros.h"
130-#include "cscluts.h"
131-#include "csstrings.h"
132-#include "csfonts.h"
133-#include "cspixels.h"
134-#include "csalerts.h"
135-#include "csdialogs.h"
136-#include "csmisc.h"
137-
138-
139-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+// Loren Petrich: the author(s) of the "cseries" files is not given, but is probably
22+// either Bo Lindbergh, Mihai Parparita, or both, given their efforts in getting the
23+// code working initially.
24+// AS: It was almost certainly Bo Lindbergh
25+#ifndef _CSERIES
26+#define _CSERIES
27+
28+#ifdef HAVE_CONFIG_H
29+#include "config.h"
30+#else
31+#define VERSION "unknown version"
32+#endif
33+
34+#include <SDL.h>
35+#include <SDL_byteorder.h>
36+#include <time.h>
37+#include <string>
38+
39+#define DEBUG
40+
41+#ifndef __MVCPP__
42+
43+// mwcc doesn't accept "using namespace std;" otherwise
44+namespace std {};
45+
46+#elif __MVCPP__
47+
48+using namespace std; // Visual C++ doesn't like that other way of using the namespace.
49+#if _MSC_VER < 1300
50+#define for if(false) {} else for // solves a bug in MSVC prior to MSVC7 for the "redeclared" initializers used in for loops.
51+#endif
52+
53+//#define VERSION "1.0"
54+
55+#endif
56+
57+/*
58+ * Endianess definitions
59+ */
60+
61+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
62+#define ALEPHONE_LITTLE_ENDIAN 1
63+#else
64+#undef ALEPHONE_LITTLE_ENDIAN
65+#endif
66+
67+
68+/*
69+ * Data types with specific bit width
70+ */
71+
72+#include "cstypes.h"
73+
74+/*
75+ * Emulation of MacOS data types and definitions
76+ */
77+#if !defined(SDL_RFORK_HACK)// && !defined(TARGET_API_MAC_CARBON)
78+
79+#if defined(__APPLE__) && defined(__MACH__)
80+// if we're on the right platform, we can use the real thing (and get headers for functions we might want to use)
81+#include <CoreFoundation/CoreFoundation.h>
82+#elif !defined(TARGET_API_MAC_CARBON)
83+typedef int OSErr;
84+typedef unsigned char Str255[256];
85+
86+struct Rect {
87+ int16 top, left;
88+ int16 bottom, right;
89+};
90+
91+const int noErr = 0;
92+#endif
93+
94+struct RGBColor {
95+ uint16 red, green, blue;
96+};
97+
98+const int kFontIDMonaco = 4;
99+const int kFontIDCourier = 22;
100+
101+#else
102+# if !defined(TARGET_API_MAC_CARBON)
103+# define DEBUGASSERTMSG
104+# endif
105+# ifdef DEBUG
106+# define WAS_DEBUG
107+//AS: this is ugly...
108+
109+# undef DEBUG
110+# endif
111+# if !defined(TARGET_API_MAC_CARBON)
112+# define dialog CHEESEOFDEATH
113+# define DialogPtr mDialogPtr
114+# include <MacTypes.h>
115+# include <Quickdraw.h>
116+# undef dialog
117+# undef DialogPtr
118+# endif
119+# ifdef WAS_DEBUG
120+# define DEBUG
121+# endif
122+#endif
123+
124+/*
125+ * Include CSeries headers
126+ */
127+
128+#include "cstypes.h"
129+#include "csmacros.h"
130+#include "cscluts.h"
131+#include "csstrings.h"
132+#include "csfonts.h"
133+#include "cspixels.h"
134+#include "csalerts.h"
135+#include "csdialogs.h"
136+#include "csmisc.h"
137+
138+
139+#endif
--- marathon/trunk/Source_Files/CSeries/gdspec.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/gdspec.cpp (revision 522)
@@ -1,697 +1,697 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20- Changes:
21-
22-Jan 30, 2000 (Loren Petrich)
23- Did some typecasts
24-
25-Jan 25, 2002 (Br'fin (Jeremy Parsons)):
26- Added TARGET_API_MAC_CARBON for Carbon.h
27- Added accessors for datafields now opaque in Carbon
28- Carbon proc routines all allocated as UPP's
29- GetSlotFromGDevice does nothing under Carbon (Slot field now opaque)
30-
31-Feb 5, 2002 (Br'fin (Jeremy Parsons)):
32- Put screen choosing dialog in a sheet under Carbon
33-
34-Feb 14, 2002 (Br'fin (Jeremy Parsons)):
35- Made the Carbon sheet background transparent
36- Changed the background for the screen selector to be an opaque backgrounded image well in Carbon
37-*/
38-
39-#include <stdlib.h>
40-#include <vector>
41-
42-#include "cseries.h"
43-#include "shell.h"
44-
45-#ifdef USES_NIBS
46- #include "NibsUiHelpers.h"
47-#endif
48-
49-GDHandle BestDevice(
50- GDSpecPtr spec)
51-{
52- GDHandle dev;
53- GDHandle first;
54- Rect bounds;
55-
56- first=NULL;
57- for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
58- if (!TestDeviceAttribute(dev,screenDevice)
59- || !TestDeviceAttribute(dev,screenActive))
60- continue;
61- bounds=(*dev)->gdRect;
62- if (bounds.right-bounds.left<spec->width
63- || bounds.bottom-bounds.top<spec->height
64- || !HasDepth(dev,spec->bit_depth,1<<gdDevType,spec->flags))
65- continue;
66- if (GetSlotFromGDevice(dev)==spec->slot) {
67- first=dev;
68- break;
69- }
70- if (!first)
71- first=dev;
72- }
73- if (first)
74- spec->slot=GetSlotFromGDevice(first);
75- return first;
76-}
77-
78-GDHandle MatchGDSpec(
79- GDSpecPtr spec)
80-{
81- GDHandle dev;
82-
83- for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
84- if (!TestDeviceAttribute(dev,screenDevice)
85- || !TestDeviceAttribute(dev,screenActive))
86- continue;
87- if (GetSlotFromGDevice(dev)==spec->slot)
88- return dev;
89- }
90- return NULL;
91-}
92-
93-void SetDepthGDSpec(
94- GDSpecPtr spec)
95-{
96- GDHandle dev;
97-
98- for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
99- if (!TestDeviceAttribute(dev,screenDevice)
100- || !TestDeviceAttribute(dev,screenActive))
101- continue;
102- if (GetSlotFromGDevice(dev)==spec->slot)
103- break;
104- }
105- if (!dev)
106- return;
107- if ((*(*dev)->gdPMap)->pixelSize==spec->bit_depth
108- && !!TestDeviceAttribute(dev,gdDevType)==!!(spec->flags&1<<gdDevType))
109- return;
110- SetDepth(dev,spec->bit_depth,1<<gdDevType,spec->flags);
111-}
112-
113-void BuildGDSpec(
114- GDSpecPtr spec,
115- GDHandle dev)
116-{
117- Rect bounds;
118-
119- spec->slot=GetSlotFromGDevice(dev);
120- spec->flags=TestDeviceAttribute(dev,gdDevType) ? 1<<gdDevType : 0;
121- spec->bit_depth=(*(*dev)->gdPMap)->pixelSize;
122- bounds=(*dev)->gdRect;
123- spec->width=bounds.right-bounds.left;
124- spec->height=bounds.bottom-bounds.top;
125-}
126-
127-bool HasDepthGDSpec(
128- GDSpecPtr spec)
129-{
130- GDHandle dev;
131-
132- for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
133- if (!TestDeviceAttribute(dev,screenDevice)
134- || !TestDeviceAttribute(dev,screenActive))
135- continue;
136- if (GetSlotFromGDevice(dev)==spec->slot)
137- break;
138- }
139- if (!dev)
140- return false;
141-/* the comments in screen.c indicate that the colours/grays bit should not be tested */
142- return !!HasDepth(dev,spec->bit_depth,0,0);
143-}
144-
145-bool EqualGDSpec(
146- GDSpecPtr spec1,
147- GDSpecPtr spec2)
148-{
149- return spec1->slot==spec2->slot;
150-}
151-
152-short GetSlotFromGDevice(
153- GDHandle cur_dev)
154-{
155-#if defined(TARGET_API_MAC_CARBON)
156- short count= 0;
157- GDHandle dev;
158- for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev), ++count) {
159- if (!TestDeviceAttribute(dev,screenDevice)
160- || !TestDeviceAttribute(dev,screenActive))
161- continue;
162- if(dev == cur_dev)
163- {
164- break;
165- }
166- }
167- return count;
168-#else
169- return (*(AuxDCEHandle)GetDCtlEntry((*dev)->gdRefNum))->dCtlSlot;
170-#endif
171-}
172-
173-enum {
174- dlgScreenChooser=20000,
175-
176- itemOKButton=1,
177- itemCancelButton,
178- itemColorsRadio,
179- itemGraysRadio,
180- itemDesktopUser,
181- itemPromptText,
182- itemGroupUser, // In the nib version, contains the gray and color radio buttons
183- itemGroupText,
184- itemDescriptionText
185-};
186-
187-#ifdef USES_NIBS
188-
189-const CFStringRef Window_Prefs_Monitor = CFSTR("Prefs_Monitor");
190-
191-
192-// For the grays/colors radio button
193-enum
194-{
195- rbColor = 1,
196- rbGray
197-};
198-
199-
200-// For the data to be attached to the monitor controls as properties
201-const OSType AppTag = 'appl';
202-const OSType DevInfoTag = 'dvif';
203-
204-const OSType Monitor_Sig = 'mnsg';
205-
206-struct DevInfo {
207- ControlRef Ctrl;
208- GDHandle Dev;
209- Rect Bounds;
210- bool IsSelected;
211- bool HasMenu;
212-};
213-
214-
215-struct DesktopDisplayData
216-{
217- vector<DevInfo> Devices;
218-};
219-
220-
221-static void MonitorDrawer(ControlRef Ctrl, void *Data)
222-{
223- DevInfo *DI_Ptr = (DevInfo *)Data;
224-
225- // No need for the window context -- it's assumed
226- Rect Bounds = {0,0,0,0};
227-
228- GetControlBounds(Ctrl, &Bounds);
229-
230- // Get ready to draw the swatch
231- PenNormal();
232-
233- // Draw!
234- const RGBColor SelColor = {0xc000,0xffff,0xc000};
235- const RGBColor UnselColor = {0x4000,0x4000,0xffff};
236- const RGBColor *ColorPtr = (DI_Ptr->IsSelected) ? &SelColor : &UnselColor;
237-
238- RGBForeColor(ColorPtr);
239- PaintRect(&Bounds);
240- ForeColor(blackColor);
241- FrameRect(&Bounds);
242-
243- if (DI_Ptr->HasMenu)
244- {
245- const short MenuThickness = 4;
246- Bounds.bottom = Bounds.top + MenuThickness;
247- ForeColor(whiteColor);
248- PaintRect(&Bounds);
249- ForeColor(blackColor);
250- FrameRect(&Bounds);
251- }
252-}
253-
254-
255-static void MonitorHandler(ParsedControl &Ctrl, void *Data)
256-{
257- DesktopDisplayData *DDPtr = (DesktopDisplayData *)(Data);
258-
259- if (Ctrl.ID.signature == Monitor_Sig)
260- {
261- for (int k=0; k<DDPtr->Devices.size(); k++)
262- {
263- DDPtr->Devices[k].IsSelected = (k == Ctrl.ID.id);
264- Draw1Control(DDPtr->Devices[k].Ctrl);
265- }
266- }
267-}
268-
269-
270-struct PositioningInfo
271-{
272- float Center_H;
273- float Center_V;
274- float Size_H;
275- float Size_V;
276-
277- PositioningInfo(Rect &R);
278-};
279-
280-PositioningInfo::PositioningInfo(Rect &R)
281-{
282- Center_H = 0.5*(R.left + R.right);
283- Center_V = 0.5*(R.top + R.bottom);
284-
285- Size_H = R.right - R.left;
286- Size_V = R.bottom - R.top;
287-}
288-
289-void display_device_dialog(
290- GDSpecPtr spec)
291-{
292- OSStatus err;
293-
294- // Get the window
295- AutoNibReference Nib (Window_Prefs_Monitor);
296- AutoNibWindow Window (Nib.nibReference (), Window_Prefs_Monitor);
297-
298- // Get its controls
299-
300- ControlRef GrayColorCtrl = GetCtrlFromWindow(Window(),0,itemGroupUser);
301- SetControl32BitValue(GrayColorCtrl,rbColor);
302-
303- DesktopDisplayData DesktopData;
304- ControlRef DesktopCtrl = GetCtrlFromWindow(Window(),0,itemDesktopUser);
305-
306- Rect DesktopBounds;
307- GetControlBounds(DesktopCtrl, &DesktopBounds);
308-
309- // Create inset version for putting the monitors in
310- const short InsetAmount = 8;
311- InsetRect(&DesktopBounds,InsetAmount,InsetAmount);
312-
313- // For making controls drawable and hittable
314- AutoDrawability Drawability;
315- AutoHittability Hittability;
316-
317- // Light gray
318- RGBColor DesktopColor = {0xe800, 0xe800, 0xe800};
319-
320- Drawability(DesktopCtrl, SwatchDrawer, &DesktopColor);
321-
322- // Compose the monitor representations
323-
324- GDHandle MainDev = GetMainDevice();
325-
326- // The total screen area
327- Rect TotalBounds;
328- TotalBounds.left = TotalBounds.top = 0x7fff;
329- TotalBounds.right = TotalBounds.bottom = 0x8000;
330-
331- // Pick up the device info
332- for (GDHandle Dev = GetDeviceList(); Dev; Dev = GetNextDevice(Dev))
333- {
334- // Skip over non-monitors and inactive monitors
335- if (!TestDeviceAttribute(Dev,screenDevice) ||
336- !TestDeviceAttribute(Dev,screenActive)) continue;
337-
338- DevInfo Monitor;
339-
340- Monitor.Dev = Dev;
341-
342- Monitor.Bounds = (*Dev)->gdRect;
343- UnionRect(&TotalBounds, &Monitor.Bounds, &TotalBounds);
344-
345- Monitor.IsSelected = (GetSlotFromGDevice(Dev)==spec->slot);
346-
347- Monitor.HasMenu = (Dev == MainDev);
348-
349- // Add to list
350- DesktopData.Devices.push_back(Monitor);
351- }
352-
353- // Set up scaling factors
354- PositioningInfo Total_PInfo(TotalBounds);
355- PositioningInfo Desktop_PInfo(DesktopBounds);
356-
357- float Scale_H = Desktop_PInfo.Size_H/Total_PInfo.Size_H;
358- float Scale_V = Desktop_PInfo.Size_V/Total_PInfo.Size_V;
359- float Scale = MIN(Scale_H,Scale_V);
360-
361- // Create monitor controls
362-
363- int k = 0;
364- for (vector<DevInfo>::iterator DI_Iter = DesktopData.Devices.begin();
365- DI_Iter < DesktopData.Devices.end();
366- DI_Iter++, k++)
367- {
368- // Find appropriately-scaled bounds for representing the monitor
369- Rect Bounds;
370- // The 0.5 factor is for rounding off of nonnegative values
371- Bounds.left =
372- Scale*(DI_Iter->Bounds.left - Total_PInfo.Center_H) + Desktop_PInfo.Center_H + 0.5;
373- Bounds.right =
374- Scale*(DI_Iter->Bounds.right - Total_PInfo.Center_H) + Desktop_PInfo.Center_H + 0.5;
375- Bounds.top =
376- Scale*(DI_Iter->Bounds.top - Total_PInfo.Center_V) + Desktop_PInfo.Center_V + 0.5;
377- Bounds.bottom =
378- Scale*(DI_Iter->Bounds.bottom - Total_PInfo.Center_V) + Desktop_PInfo.Center_V + 0.5;
379-
380- // Create!
381- err = CreateUserPaneControl(
382- Window(), &Bounds,
383- 0, &(DI_Iter->Ctrl)
384- );
385- vassert(err == noErr, csprintf(temporary,"CreateUserPaneControl error: %d",(int)err));
386-
387- // Add ID so that the dialog's hit tester can recognize it
388- ControlID ID;
389- ID.signature = Monitor_Sig;
390- ID.id = k;
391-
392- err = SetControlID(DI_Iter->Ctrl, &ID);
393- vassert(err == noErr, csprintf(temporary,"SetControlID error: %d",(int)err));
394-
395- // OK since the list of device-info data is now set up
396- // and will not get reallocated
397- Drawability(DI_Iter->Ctrl, MonitorDrawer, &DesktopData.Devices[k]);
398- Hittability(DI_Iter->Ctrl);
399-
400- EmbedControl(DI_Iter->Ctrl, DesktopCtrl);
401- }
402-
403- if (RunModalDialog(Window(), true, MonitorHandler, &DesktopData))
404- {
405- // Pressed "OK" -- get the selected device
406-
407- for (vector<DevInfo>::iterator DI_Iter = DesktopData.Devices.begin(); DI_Iter < DesktopData.Devices.end(); DI_Iter++)
408- {
409- if (DI_Iter->IsSelected)
410- spec->slot = GetSlotFromGDevice(DI_Iter->Dev);
411- }
412- spec->flags = (GetControl32BitValue(GrayColorCtrl) == rbColor) ? 1<<gdDevType : 0;
413- }
414-}
415-
416-
417-#else
418-
419-typedef struct dev_info {
420- Rect rect;
421- GDHandle dev;
422-} dev_info;
423-
424-static dev_info *devices;
425-static short devcnt;
426-static short mainix;
427-static short curix;
428-
429-static pascal void draw_desktop(
430- DialogPtr dlg,
431- short item)
432-{
433- int i;
434- short it;
435- Handle ih;
436- Rect ir;
437- static RGBColor fifty={0x7FFF,0x7FFF,0x7FFF};
438-
439- GetDialogItem(dlg,item,&it,&ih,&ir);
440-#if defined(TARGET_API_MAC_CARBON)
441- CGrafPtr port = GetWindowPort(GetDialogWindow(dlg));
442- SInt16 pixelDepth = (*GetPortPixMap(port))->pixelSize;
443-
444- ThemeDrawingState savedState;
445- ThemeDrawState curState =
446- IsWindowActive(GetDialogWindow(dlg))?kThemeStateActive:kThemeStateInactive;
447-
448- GetThemeDrawingState(&savedState);
449- SetThemeBackground(
450- (curState == kThemeStateActive)?kThemeBrushDialogBackgroundActive:kThemeBrushDialogBackgroundInactive,
451- pixelDepth, pixelDepth > 1);
452- EraseRect(&ir);
453- DrawThemeGenericWell (&ir, curState, false);
454- SetThemeDrawingState(savedState, true);
455-#else
456- FrameRect(&ir);
457-#endif
458- for (i=0; i<devcnt; i++) {
459- ir=devices[i].rect;
460- if (i==curix) {
461- PenSize(2,2);
462- InsetRect(&ir,2,2);
463- } else {
464- PenSize(1,1);
465- InsetRect(&ir,1,1);
466- }
467- RGBForeColor(&fifty);
468- PaintRect(&ir);
469- ForeColor(blackColor);
470- FrameRect(&devices[i].rect);
471- PenSize(1,1);
472- if (i==mainix) {
473- ir=devices[i].rect;
474- InsetRect(&ir,1,1);
475- ir.bottom=ir.top+4;
476- ForeColor(whiteColor);
477- PaintRect(&ir);
478- ForeColor(blackColor);
479- MoveTo(ir.left,ir.bottom);
480- LineTo(ir.right-1,ir.bottom);
481- }
482- }
483-}
484-
485-#if defined(TARGET_API_MAC_CARBON)
486-UserItemUPP draw_desktop_upp = NewUserItemUPP(draw_desktop);
487-#else
488-#if GENERATINGCFM
489-static RoutineDescriptor draw_desktop_desc =
490- BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo,draw_desktop);
491-#define draw_desktop_upp (&draw_desktop_desc)
492-#else
493-#define draw_desktop_upp draw_desktop
494-#endif
495-#endif
496-
497-static pascal void draw_group(
498- DialogPtr dlg,
499- short item)
500-{
501- short it;
502- Handle ih;
503- Rect ir;
504- RgnHandle outer,inner;
505- static RGBColor third={0x5555,0x5555,0x5555};
506-
507- inner=NewRgn();
508- outer=NewRgn();
509- GetDialogItem(dlg,item,&it,&ih,&ir);
510- RectRgn(outer,&ir);
511- InsetRect(&ir,1,1);
512- RectRgn(inner,&ir);
513- DiffRgn(outer,inner,outer);
514- GetDialogItem(dlg,item+1,&it,&ih,&ir);
515- RectRgn(inner,&ir);
516- DiffRgn(outer,inner,outer);
517- DisposeRgn(inner);
518- RGBForeColor(&third);
519- PaintRgn(outer);
520- ForeColor(blackColor);
521- DisposeRgn(outer);
522-}
523-
524-#if defined(TARGET_API_MAC_CARBON)
525-UserItemUPP draw_group_upp = NewUserItemUPP(draw_group);
526-#else
527-#if GENERATINGCFM
528-static RoutineDescriptor draw_group_desc =
529- BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo,draw_group);
530-#define draw_group_upp (&draw_group_desc)
531-#else
532-#define draw_group_upp draw_group
533-#endif
534-#endif
535-
536-static pascal Boolean device_filter(
537- DialogPtr dlg,
538- EventRecord *event,
539- short *hit)
540-{
541- WindowPtr win;
542- int item;
543- Point where;
544- GrafPtr saveport;
545- int i;
546-
547- switch (event->what) {
548- case mouseDown:
549- switch (FindWindow(event->where,&win)) {
550- case inContent:
551- where=event->where;
552- GetPort(&saveport);
553- SetPort(GetWindowPort(GetDialogWindow(dlg)));
554-
555- GlobalToLocal(&where);
556- item=FindDialogItem(dlg,where)+1;
557- switch (item) {
558- case itemDesktopUser:
559- for (i=0; i<devcnt; i++) {
560- if (PtInRect(where,&devices[i].rect)) {
561- if (curix!=i) {
562- curix=i;
563- draw_desktop(dlg,itemDesktopUser);
564- }
565- break;
566- }
567- }
568- break;
569- }
570- SetPort(saveport);
571- break;
572- }
573- break;
574- }
575- return general_filter_proc(dlg,event,hit);
576-}
577-
578-#if defined(TARGET_API_MAC_CARBON)
579-ModalFilterUPP device_filter_upp = NewModalFilterUPP(device_filter);
580-#else
581-#if GENERATINGCFM
582-static RoutineDescriptor device_filter_desc =
583- BUILD_ROUTINE_DESCRIPTOR(uppModalFilterProcInfo,device_filter);
584-#define device_filter_upp (&device_filter_desc)
585-#else
586-#define device_filter_upp device_filter
587-#endif
588-#endif
589-
590-void display_device_dialog(
591- GDSpecPtr spec)
592-{
593- DialogPtr dlg;
594- short it;
595- Handle ih;
596- Rect ir;
597- GDHandle dev,maindev;
598- int i,cnt;
599- Rect one,all,small;
600- int width,height;
601- ControlHandle graysradio,colorsradio;
602- bool done;
603- short hit;
604-
605- maindev=GetMainDevice();
606- dlg=myGetNewDialog(dlgScreenChooser,NULL,(WindowPtr)-1,0);
607- assert(dlg);
608-/*
609- GetDialogItem(dlg,itemGroupUser,&it,&ih,&ir);
610- SetDialogItem(dlg,itemGroupUser,kUserDialogItem|kItemDisableBit,
611- (Handle)draw_group_upp,&ir);
612-*/
613- GetDialogItem(dlg,itemDesktopUser,&it,&ih,&ir);
614- SetDialogItem(dlg,itemDesktopUser,kUserDialogItem|kItemDisableBit,
615- (Handle)draw_desktop_upp,&ir);
616- cnt=0;
617- all.left=all.top=0x7FFF;
618- all.right=all.bottom=0x8000;
619- for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
620- if (!TestDeviceAttribute(dev,screenDevice)
621- || !TestDeviceAttribute(dev,screenActive))
622- continue;
623- one=(*dev)->gdRect;
624- UnionRect(&all,&one,&all);
625- cnt++;
626- }
627- width=all.right-all.left>>4;
628- height=all.bottom-all.top>>4;
629- small.left=(ir.left+ir.right-width)/2;
630- small.top=(ir.top+ir.bottom-height)/2;
631- small.right=small.left+width;
632- small.bottom=small.top+height;
633- devices= new dev_info[cnt];
634- assert(devices);
635- devcnt=cnt;
636- i=0;
637- mainix=NONE;
638- curix=NONE;
639- for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
640- if (!TestDeviceAttribute(dev,screenDevice)
641- || !TestDeviceAttribute(dev,screenActive))
642- continue;
643- devices[i].rect=(*dev)->gdRect;
644- MapRect(&devices[i].rect,&all,&small);
645- devices[i].dev=dev;
646- if (dev==maindev)
647- mainix=i;
648- if (GetSlotFromGDevice(dev)==spec->slot)
649- curix=i;
650- i++;
651- }
652- if (curix==NONE)
653- curix=mainix;
654- GetDialogItem(dlg,itemGraysRadio,&it,&ih,&ir);
655- graysradio=(ControlHandle)ih;
656- GetDialogItem(dlg,itemColorsRadio,&it,&ih,&ir);
657- colorsradio=(ControlHandle)ih;
658- SetControlValue((spec->flags&1<<gdDevType) ? colorsradio : graysradio,1);
659-#if USE_SHEETS
660- SetThemeWindowBackground(GetDialogWindow(dlg), kThemeBrushSheetBackgroundTransparent, false);
661- ShowSheetWindow(GetDialogWindow(dlg), ActiveNonFloatingWindow());
662-#else
663- ShowWindow(GetDialogWindow(dlg));
664-#endif
665-
666- for (done=false; !done; ) {
667- ModalDialog(device_filter_upp,&hit);
668- switch (hit) {
669- case itemOKButton:
670- case itemCancelButton:
671- done=true;
672- break;
673- case itemColorsRadio:
674- SetControlValue(graysradio,0);
675- SetControlValue(colorsradio,1);
676- break;
677- case itemGraysRadio:
678- SetControlValue(colorsradio,0);
679- SetControlValue(graysradio,1);
680- break;
681- }
682- }
683-#if USE_SHEETS
684- HideSheetWindow(GetDialogWindow(dlg));
685-#else
686- HideWindow(GetDialogWindow(dlg));
687-#endif
688-
689- if (hit==itemOKButton) {
690- spec->slot=GetSlotFromGDevice(devices[curix].dev);
691- spec->flags=GetControlValue(colorsradio) ? 1<<gdDevType : 0;
692- }
693- delete []devices;
694- DisposeDialog(dlg);
695-}
696-
697-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+ Changes:
21+
22+Jan 30, 2000 (Loren Petrich)
23+ Did some typecasts
24+
25+Jan 25, 2002 (Br'fin (Jeremy Parsons)):
26+ Added TARGET_API_MAC_CARBON for Carbon.h
27+ Added accessors for datafields now opaque in Carbon
28+ Carbon proc routines all allocated as UPP's
29+ GetSlotFromGDevice does nothing under Carbon (Slot field now opaque)
30+
31+Feb 5, 2002 (Br'fin (Jeremy Parsons)):
32+ Put screen choosing dialog in a sheet under Carbon
33+
34+Feb 14, 2002 (Br'fin (Jeremy Parsons)):
35+ Made the Carbon sheet background transparent
36+ Changed the background for the screen selector to be an opaque backgrounded image well in Carbon
37+*/
38+
39+#include <stdlib.h>
40+#include <vector>
41+
42+#include "cseries.h"
43+#include "shell.h"
44+
45+#ifdef USES_NIBS
46+ #include "NibsUiHelpers.h"
47+#endif
48+
49+GDHandle BestDevice(
50+ GDSpecPtr spec)
51+{
52+ GDHandle dev;
53+ GDHandle first;
54+ Rect bounds;
55+
56+ first=NULL;
57+ for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
58+ if (!TestDeviceAttribute(dev,screenDevice)
59+ || !TestDeviceAttribute(dev,screenActive))
60+ continue;
61+ bounds=(*dev)->gdRect;
62+ if (bounds.right-bounds.left<spec->width
63+ || bounds.bottom-bounds.top<spec->height
64+ || !HasDepth(dev,spec->bit_depth,1<<gdDevType,spec->flags))
65+ continue;
66+ if (GetSlotFromGDevice(dev)==spec->slot) {
67+ first=dev;
68+ break;
69+ }
70+ if (!first)
71+ first=dev;
72+ }
73+ if (first)
74+ spec->slot=GetSlotFromGDevice(first);
75+ return first;
76+}
77+
78+GDHandle MatchGDSpec(
79+ GDSpecPtr spec)
80+{
81+ GDHandle dev;
82+
83+ for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
84+ if (!TestDeviceAttribute(dev,screenDevice)
85+ || !TestDeviceAttribute(dev,screenActive))
86+ continue;
87+ if (GetSlotFromGDevice(dev)==spec->slot)
88+ return dev;
89+ }
90+ return NULL;
91+}
92+
93+void SetDepthGDSpec(
94+ GDSpecPtr spec)
95+{
96+ GDHandle dev;
97+
98+ for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
99+ if (!TestDeviceAttribute(dev,screenDevice)
100+ || !TestDeviceAttribute(dev,screenActive))
101+ continue;
102+ if (GetSlotFromGDevice(dev)==spec->slot)
103+ break;
104+ }
105+ if (!dev)
106+ return;
107+ if ((*(*dev)->gdPMap)->pixelSize==spec->bit_depth
108+ && !!TestDeviceAttribute(dev,gdDevType)==!!(spec->flags&1<<gdDevType))
109+ return;
110+ SetDepth(dev,spec->bit_depth,1<<gdDevType,spec->flags);
111+}
112+
113+void BuildGDSpec(
114+ GDSpecPtr spec,
115+ GDHandle dev)
116+{
117+ Rect bounds;
118+
119+ spec->slot=GetSlotFromGDevice(dev);
120+ spec->flags=TestDeviceAttribute(dev,gdDevType) ? 1<<gdDevType : 0;
121+ spec->bit_depth=(*(*dev)->gdPMap)->pixelSize;
122+ bounds=(*dev)->gdRect;
123+ spec->width=bounds.right-bounds.left;
124+ spec->height=bounds.bottom-bounds.top;
125+}
126+
127+bool HasDepthGDSpec(
128+ GDSpecPtr spec)
129+{
130+ GDHandle dev;
131+
132+ for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
133+ if (!TestDeviceAttribute(dev,screenDevice)
134+ || !TestDeviceAttribute(dev,screenActive))
135+ continue;
136+ if (GetSlotFromGDevice(dev)==spec->slot)
137+ break;
138+ }
139+ if (!dev)
140+ return false;
141+/* the comments in screen.c indicate that the colours/grays bit should not be tested */
142+ return !!HasDepth(dev,spec->bit_depth,0,0);
143+}
144+
145+bool EqualGDSpec(
146+ GDSpecPtr spec1,
147+ GDSpecPtr spec2)
148+{
149+ return spec1->slot==spec2->slot;
150+}
151+
152+short GetSlotFromGDevice(
153+ GDHandle cur_dev)
154+{
155+#if defined(TARGET_API_MAC_CARBON)
156+ short count= 0;
157+ GDHandle dev;
158+ for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev), ++count) {
159+ if (!TestDeviceAttribute(dev,screenDevice)
160+ || !TestDeviceAttribute(dev,screenActive))
161+ continue;
162+ if(dev == cur_dev)
163+ {
164+ break;
165+ }
166+ }
167+ return count;
168+#else
169+ return (*(AuxDCEHandle)GetDCtlEntry((*dev)->gdRefNum))->dCtlSlot;
170+#endif
171+}
172+
173+enum {
174+ dlgScreenChooser=20000,
175+
176+ itemOKButton=1,
177+ itemCancelButton,
178+ itemColorsRadio,
179+ itemGraysRadio,
180+ itemDesktopUser,
181+ itemPromptText,
182+ itemGroupUser, // In the nib version, contains the gray and color radio buttons
183+ itemGroupText,
184+ itemDescriptionText
185+};
186+
187+#ifdef USES_NIBS
188+
189+const CFStringRef Window_Prefs_Monitor = CFSTR("Prefs_Monitor");
190+
191+
192+// For the grays/colors radio button
193+enum
194+{
195+ rbColor = 1,
196+ rbGray
197+};
198+
199+
200+// For the data to be attached to the monitor controls as properties
201+const OSType AppTag = 'appl';
202+const OSType DevInfoTag = 'dvif';
203+
204+const OSType Monitor_Sig = 'mnsg';
205+
206+struct DevInfo {
207+ ControlRef Ctrl;
208+ GDHandle Dev;
209+ Rect Bounds;
210+ bool IsSelected;
211+ bool HasMenu;
212+};
213+
214+
215+struct DesktopDisplayData
216+{
217+ vector<DevInfo> Devices;
218+};
219+
220+
221+static void MonitorDrawer(ControlRef Ctrl, void *Data)
222+{
223+ DevInfo *DI_Ptr = (DevInfo *)Data;
224+
225+ // No need for the window context -- it's assumed
226+ Rect Bounds = {0,0,0,0};
227+
228+ GetControlBounds(Ctrl, &Bounds);
229+
230+ // Get ready to draw the swatch
231+ PenNormal();
232+
233+ // Draw!
234+ const RGBColor SelColor = {0xc000,0xffff,0xc000};
235+ const RGBColor UnselColor = {0x4000,0x4000,0xffff};
236+ const RGBColor *ColorPtr = (DI_Ptr->IsSelected) ? &SelColor : &UnselColor;
237+
238+ RGBForeColor(ColorPtr);
239+ PaintRect(&Bounds);
240+ ForeColor(blackColor);
241+ FrameRect(&Bounds);
242+
243+ if (DI_Ptr->HasMenu)
244+ {
245+ const short MenuThickness = 4;
246+ Bounds.bottom = Bounds.top + MenuThickness;
247+ ForeColor(whiteColor);
248+ PaintRect(&Bounds);
249+ ForeColor(blackColor);
250+ FrameRect(&Bounds);
251+ }
252+}
253+
254+
255+static void MonitorHandler(ParsedControl &Ctrl, void *Data)
256+{
257+ DesktopDisplayData *DDPtr = (DesktopDisplayData *)(Data);
258+
259+ if (Ctrl.ID.signature == Monitor_Sig)
260+ {
261+ for (int k=0; k<DDPtr->Devices.size(); k++)
262+ {
263+ DDPtr->Devices[k].IsSelected = (k == Ctrl.ID.id);
264+ Draw1Control(DDPtr->Devices[k].Ctrl);
265+ }
266+ }
267+}
268+
269+
270+struct PositioningInfo
271+{
272+ float Center_H;
273+ float Center_V;
274+ float Size_H;
275+ float Size_V;
276+
277+ PositioningInfo(Rect &R);
278+};
279+
280+PositioningInfo::PositioningInfo(Rect &R)
281+{
282+ Center_H = 0.5*(R.left + R.right);
283+ Center_V = 0.5*(R.top + R.bottom);
284+
285+ Size_H = R.right - R.left;
286+ Size_V = R.bottom - R.top;
287+}
288+
289+void display_device_dialog(
290+ GDSpecPtr spec)
291+{
292+ OSStatus err;
293+
294+ // Get the window
295+ AutoNibReference Nib (Window_Prefs_Monitor);
296+ AutoNibWindow Window (Nib.nibReference (), Window_Prefs_Monitor);
297+
298+ // Get its controls
299+
300+ ControlRef GrayColorCtrl = GetCtrlFromWindow(Window(),0,itemGroupUser);
301+ SetControl32BitValue(GrayColorCtrl,rbColor);
302+
303+ DesktopDisplayData DesktopData;
304+ ControlRef DesktopCtrl = GetCtrlFromWindow(Window(),0,itemDesktopUser);
305+
306+ Rect DesktopBounds;
307+ GetControlBounds(DesktopCtrl, &DesktopBounds);
308+
309+ // Create inset version for putting the monitors in
310+ const short InsetAmount = 8;
311+ InsetRect(&DesktopBounds,InsetAmount,InsetAmount);
312+
313+ // For making controls drawable and hittable
314+ AutoDrawability Drawability;
315+ AutoHittability Hittability;
316+
317+ // Light gray
318+ RGBColor DesktopColor = {0xe800, 0xe800, 0xe800};
319+
320+ Drawability(DesktopCtrl, SwatchDrawer, &DesktopColor);
321+
322+ // Compose the monitor representations
323+
324+ GDHandle MainDev = GetMainDevice();
325+
326+ // The total screen area
327+ Rect TotalBounds;
328+ TotalBounds.left = TotalBounds.top = 0x7fff;
329+ TotalBounds.right = TotalBounds.bottom = 0x8000;
330+
331+ // Pick up the device info
332+ for (GDHandle Dev = GetDeviceList(); Dev; Dev = GetNextDevice(Dev))
333+ {
334+ // Skip over non-monitors and inactive monitors
335+ if (!TestDeviceAttribute(Dev,screenDevice) ||
336+ !TestDeviceAttribute(Dev,screenActive)) continue;
337+
338+ DevInfo Monitor;
339+
340+ Monitor.Dev = Dev;
341+
342+ Monitor.Bounds = (*Dev)->gdRect;
343+ UnionRect(&TotalBounds, &Monitor.Bounds, &TotalBounds);
344+
345+ Monitor.IsSelected = (GetSlotFromGDevice(Dev)==spec->slot);
346+
347+ Monitor.HasMenu = (Dev == MainDev);
348+
349+ // Add to list
350+ DesktopData.Devices.push_back(Monitor);
351+ }
352+
353+ // Set up scaling factors
354+ PositioningInfo Total_PInfo(TotalBounds);
355+ PositioningInfo Desktop_PInfo(DesktopBounds);
356+
357+ float Scale_H = Desktop_PInfo.Size_H/Total_PInfo.Size_H;
358+ float Scale_V = Desktop_PInfo.Size_V/Total_PInfo.Size_V;
359+ float Scale = MIN(Scale_H,Scale_V);
360+
361+ // Create monitor controls
362+
363+ int k = 0;
364+ for (vector<DevInfo>::iterator DI_Iter = DesktopData.Devices.begin();
365+ DI_Iter < DesktopData.Devices.end();
366+ DI_Iter++, k++)
367+ {
368+ // Find appropriately-scaled bounds for representing the monitor
369+ Rect Bounds;
370+ // The 0.5 factor is for rounding off of nonnegative values
371+ Bounds.left =
372+ Scale*(DI_Iter->Bounds.left - Total_PInfo.Center_H) + Desktop_PInfo.Center_H + 0.5;
373+ Bounds.right =
374+ Scale*(DI_Iter->Bounds.right - Total_PInfo.Center_H) + Desktop_PInfo.Center_H + 0.5;
375+ Bounds.top =
376+ Scale*(DI_Iter->Bounds.top - Total_PInfo.Center_V) + Desktop_PInfo.Center_V + 0.5;
377+ Bounds.bottom =
378+ Scale*(DI_Iter->Bounds.bottom - Total_PInfo.Center_V) + Desktop_PInfo.Center_V + 0.5;
379+
380+ // Create!
381+ err = CreateUserPaneControl(
382+ Window(), &Bounds,
383+ 0, &(DI_Iter->Ctrl)
384+ );
385+ vassert(err == noErr, csprintf(temporary,"CreateUserPaneControl error: %d",(int)err));
386+
387+ // Add ID so that the dialog's hit tester can recognize it
388+ ControlID ID;
389+ ID.signature = Monitor_Sig;
390+ ID.id = k;
391+
392+ err = SetControlID(DI_Iter->Ctrl, &ID);
393+ vassert(err == noErr, csprintf(temporary,"SetControlID error: %d",(int)err));
394+
395+ // OK since the list of device-info data is now set up
396+ // and will not get reallocated
397+ Drawability(DI_Iter->Ctrl, MonitorDrawer, &DesktopData.Devices[k]);
398+ Hittability(DI_Iter->Ctrl);
399+
400+ EmbedControl(DI_Iter->Ctrl, DesktopCtrl);
401+ }
402+
403+ if (RunModalDialog(Window(), true, MonitorHandler, &DesktopData))
404+ {
405+ // Pressed "OK" -- get the selected device
406+
407+ for (vector<DevInfo>::iterator DI_Iter = DesktopData.Devices.begin(); DI_Iter < DesktopData.Devices.end(); DI_Iter++)
408+ {
409+ if (DI_Iter->IsSelected)
410+ spec->slot = GetSlotFromGDevice(DI_Iter->Dev);
411+ }
412+ spec->flags = (GetControl32BitValue(GrayColorCtrl) == rbColor) ? 1<<gdDevType : 0;
413+ }
414+}
415+
416+
417+#else
418+
419+typedef struct dev_info {
420+ Rect rect;
421+ GDHandle dev;
422+} dev_info;
423+
424+static dev_info *devices;
425+static short devcnt;
426+static short mainix;
427+static short curix;
428+
429+static pascal void draw_desktop(
430+ DialogPtr dlg,
431+ short item)
432+{
433+ int i;
434+ short it;
435+ Handle ih;
436+ Rect ir;
437+ static RGBColor fifty={0x7FFF,0x7FFF,0x7FFF};
438+
439+ GetDialogItem(dlg,item,&it,&ih,&ir);
440+#if defined(TARGET_API_MAC_CARBON)
441+ CGrafPtr port = GetWindowPort(GetDialogWindow(dlg));
442+ SInt16 pixelDepth = (*GetPortPixMap(port))->pixelSize;
443+
444+ ThemeDrawingState savedState;
445+ ThemeDrawState curState =
446+ IsWindowActive(GetDialogWindow(dlg))?kThemeStateActive:kThemeStateInactive;
447+
448+ GetThemeDrawingState(&savedState);
449+ SetThemeBackground(
450+ (curState == kThemeStateActive)?kThemeBrushDialogBackgroundActive:kThemeBrushDialogBackgroundInactive,
451+ pixelDepth, pixelDepth > 1);
452+ EraseRect(&ir);
453+ DrawThemeGenericWell (&ir, curState, false);
454+ SetThemeDrawingState(savedState, true);
455+#else
456+ FrameRect(&ir);
457+#endif
458+ for (i=0; i<devcnt; i++) {
459+ ir=devices[i].rect;
460+ if (i==curix) {
461+ PenSize(2,2);
462+ InsetRect(&ir,2,2);
463+ } else {
464+ PenSize(1,1);
465+ InsetRect(&ir,1,1);
466+ }
467+ RGBForeColor(&fifty);
468+ PaintRect(&ir);
469+ ForeColor(blackColor);
470+ FrameRect(&devices[i].rect);
471+ PenSize(1,1);
472+ if (i==mainix) {
473+ ir=devices[i].rect;
474+ InsetRect(&ir,1,1);
475+ ir.bottom=ir.top+4;
476+ ForeColor(whiteColor);
477+ PaintRect(&ir);
478+ ForeColor(blackColor);
479+ MoveTo(ir.left,ir.bottom);
480+ LineTo(ir.right-1,ir.bottom);
481+ }
482+ }
483+}
484+
485+#if defined(TARGET_API_MAC_CARBON)
486+UserItemUPP draw_desktop_upp = NewUserItemUPP(draw_desktop);
487+#else
488+#if GENERATINGCFM
489+static RoutineDescriptor draw_desktop_desc =
490+ BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo,draw_desktop);
491+#define draw_desktop_upp (&draw_desktop_desc)
492+#else
493+#define draw_desktop_upp draw_desktop
494+#endif
495+#endif
496+
497+static pascal void draw_group(
498+ DialogPtr dlg,
499+ short item)
500+{
501+ short it;
502+ Handle ih;
503+ Rect ir;
504+ RgnHandle outer,inner;
505+ static RGBColor third={0x5555,0x5555,0x5555};
506+
507+ inner=NewRgn();
508+ outer=NewRgn();
509+ GetDialogItem(dlg,item,&it,&ih,&ir);
510+ RectRgn(outer,&ir);
511+ InsetRect(&ir,1,1);
512+ RectRgn(inner,&ir);
513+ DiffRgn(outer,inner,outer);
514+ GetDialogItem(dlg,item+1,&it,&ih,&ir);
515+ RectRgn(inner,&ir);
516+ DiffRgn(outer,inner,outer);
517+ DisposeRgn(inner);
518+ RGBForeColor(&third);
519+ PaintRgn(outer);
520+ ForeColor(blackColor);
521+ DisposeRgn(outer);
522+}
523+
524+#if defined(TARGET_API_MAC_CARBON)
525+UserItemUPP draw_group_upp = NewUserItemUPP(draw_group);
526+#else
527+#if GENERATINGCFM
528+static RoutineDescriptor draw_group_desc =
529+ BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo,draw_group);
530+#define draw_group_upp (&draw_group_desc)
531+#else
532+#define draw_group_upp draw_group
533+#endif
534+#endif
535+
536+static pascal Boolean device_filter(
537+ DialogPtr dlg,
538+ EventRecord *event,
539+ short *hit)
540+{
541+ WindowPtr win;
542+ int item;
543+ Point where;
544+ GrafPtr saveport;
545+ int i;
546+
547+ switch (event->what) {
548+ case mouseDown:
549+ switch (FindWindow(event->where,&win)) {
550+ case inContent:
551+ where=event->where;
552+ GetPort(&saveport);
553+ SetPort(GetWindowPort(GetDialogWindow(dlg)));
554+
555+ GlobalToLocal(&where);
556+ item=FindDialogItem(dlg,where)+1;
557+ switch (item) {
558+ case itemDesktopUser:
559+ for (i=0; i<devcnt; i++) {
560+ if (PtInRect(where,&devices[i].rect)) {
561+ if (curix!=i) {
562+ curix=i;
563+ draw_desktop(dlg,itemDesktopUser);
564+ }
565+ break;
566+ }
567+ }
568+ break;
569+ }
570+ SetPort(saveport);
571+ break;
572+ }
573+ break;
574+ }
575+ return general_filter_proc(dlg,event,hit);
576+}
577+
578+#if defined(TARGET_API_MAC_CARBON)
579+ModalFilterUPP device_filter_upp = NewModalFilterUPP(device_filter);
580+#else
581+#if GENERATINGCFM
582+static RoutineDescriptor device_filter_desc =
583+ BUILD_ROUTINE_DESCRIPTOR(uppModalFilterProcInfo,device_filter);
584+#define device_filter_upp (&device_filter_desc)
585+#else
586+#define device_filter_upp device_filter
587+#endif
588+#endif
589+
590+void display_device_dialog(
591+ GDSpecPtr spec)
592+{
593+ DialogPtr dlg;
594+ short it;
595+ Handle ih;
596+ Rect ir;
597+ GDHandle dev,maindev;
598+ int i,cnt;
599+ Rect one,all,small;
600+ int width,height;
601+ ControlHandle graysradio,colorsradio;
602+ bool done;
603+ short hit;
604+
605+ maindev=GetMainDevice();
606+ dlg=myGetNewDialog(dlgScreenChooser,NULL,(WindowPtr)-1,0);
607+ assert(dlg);
608+/*
609+ GetDialogItem(dlg,itemGroupUser,&it,&ih,&ir);
610+ SetDialogItem(dlg,itemGroupUser,kUserDialogItem|kItemDisableBit,
611+ (Handle)draw_group_upp,&ir);
612+*/
613+ GetDialogItem(dlg,itemDesktopUser,&it,&ih,&ir);
614+ SetDialogItem(dlg,itemDesktopUser,kUserDialogItem|kItemDisableBit,
615+ (Handle)draw_desktop_upp,&ir);
616+ cnt=0;
617+ all.left=all.top=0x7FFF;
618+ all.right=all.bottom=0x8000;
619+ for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
620+ if (!TestDeviceAttribute(dev,screenDevice)
621+ || !TestDeviceAttribute(dev,screenActive))
622+ continue;
623+ one=(*dev)->gdRect;
624+ UnionRect(&all,&one,&all);
625+ cnt++;
626+ }
627+ width=all.right-all.left>>4;
628+ height=all.bottom-all.top>>4;
629+ small.left=(ir.left+ir.right-width)/2;
630+ small.top=(ir.top+ir.bottom-height)/2;
631+ small.right=small.left+width;
632+ small.bottom=small.top+height;
633+ devices= new dev_info[cnt];
634+ assert(devices);
635+ devcnt=cnt;
636+ i=0;
637+ mainix=NONE;
638+ curix=NONE;
639+ for (dev=GetDeviceList(); dev; dev=GetNextDevice(dev)) {
640+ if (!TestDeviceAttribute(dev,screenDevice)
641+ || !TestDeviceAttribute(dev,screenActive))
642+ continue;
643+ devices[i].rect=(*dev)->gdRect;
644+ MapRect(&devices[i].rect,&all,&small);
645+ devices[i].dev=dev;
646+ if (dev==maindev)
647+ mainix=i;
648+ if (GetSlotFromGDevice(dev)==spec->slot)
649+ curix=i;
650+ i++;
651+ }
652+ if (curix==NONE)
653+ curix=mainix;
654+ GetDialogItem(dlg,itemGraysRadio,&it,&ih,&ir);
655+ graysradio=(ControlHandle)ih;
656+ GetDialogItem(dlg,itemColorsRadio,&it,&ih,&ir);
657+ colorsradio=(ControlHandle)ih;
658+ SetControlValue((spec->flags&1<<gdDevType) ? colorsradio : graysradio,1);
659+#if USE_SHEETS
660+ SetThemeWindowBackground(GetDialogWindow(dlg), kThemeBrushSheetBackgroundTransparent, false);
661+ ShowSheetWindow(GetDialogWindow(dlg), ActiveNonFloatingWindow());
662+#else
663+ ShowWindow(GetDialogWindow(dlg));
664+#endif
665+
666+ for (done=false; !done; ) {
667+ ModalDialog(device_filter_upp,&hit);
668+ switch (hit) {
669+ case itemOKButton:
670+ case itemCancelButton:
671+ done=true;
672+ break;
673+ case itemColorsRadio:
674+ SetControlValue(graysradio,0);
675+ SetControlValue(colorsradio,1);
676+ break;
677+ case itemGraysRadio:
678+ SetControlValue(colorsradio,0);
679+ SetControlValue(graysradio,1);
680+ break;
681+ }
682+ }
683+#if USE_SHEETS
684+ HideSheetWindow(GetDialogWindow(dlg));
685+#else
686+ HideWindow(GetDialogWindow(dlg));
687+#endif
688+
689+ if (hit==itemOKButton) {
690+ spec->slot=GetSlotFromGDevice(devices[curix].dev);
691+ spec->flags=GetControlValue(colorsradio) ? 1<<gdDevType : 0;
692+ }
693+ delete []devices;
694+ DisposeDialog(dlg);
695+}
696+
697+#endif
--- marathon/trunk/Source_Files/CSeries/cskeys.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/cskeys.h (revision 522)
@@ -1,79 +1,79 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-#ifndef _CSERIES_KEYS_
22-#define _CSERIES_KEYS_
23-
24-/*
25- [Original author not listed]
26-Feb 13, 2000 (Loren Petrich):
27- Added definitions for F-keys 13, 14, and 15; used Inside Macintosh
28- http://developer.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#HEADING40-39
29-
30-Feb 24, 2000 (Loren Petrich):
31- Gave new names to my new key definitions; they begin with "kx"
32- instead of "k". Also added kFWD_DELETE and kHELP
33-*/
34-
35-// LP changes:
36-#define kxESCAPE 0x35
37-#define kxDELETE 0x33
38-#define kxHELP 0x72
39-#define kxFWD_DELETE 0x75
40-#define kxHOME 0x73
41-#define kxEND 0x77
42-#define kxPAGE_UP 0x74
43-#define kxPAGE_DOWN 0x79
44-#define kxLEFT_ARROW 0x7B
45-#define kxRIGHT_ARROW 0x7C
46-#define kxUP_ARROW 0x7E
47-#define kxDOWN_ARROW 0x7D
48-
49-#define kDELETE 0x08
50-#define kHELP 0x05
51-#define kFWD_DELETE 0x7F
52-#define kHOME 0x01
53-#define kEND 0x04
54-#define kPAGE_UP 0x0B
55-#define kPAGE_DOWN 0x0C
56-#define kLEFT_ARROW 0x1C
57-#define kRIGHT_ARROW 0x1D
58-#define kUP_ARROW 0x1E
59-#define kDOWN_ARROW 0x1F
60-
61-
62-#define kcF1 0x7A
63-#define kcF2 0x78
64-#define kcF3 0x63
65-#define kcF4 0x76
66-#define kcF5 0x60
67-#define kcF6 0x61
68-#define kcF7 0x62
69-#define kcF8 0x64
70-#define kcF9 0x65
71-#define kcF10 0x6D
72-#define kcF11 0x67
73-#define kcF12 0x6F
74-// LP additions:
75-#define kcF13 0x69
76-#define kcF14 0x6B
77-#define kcF15 0x71
78-
79-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+#ifndef _CSERIES_KEYS_
22+#define _CSERIES_KEYS_
23+
24+/*
25+ [Original author not listed]
26+Feb 13, 2000 (Loren Petrich):
27+ Added definitions for F-keys 13, 14, and 15; used Inside Macintosh
28+ http://developer.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#HEADING40-39
29+
30+Feb 24, 2000 (Loren Petrich):
31+ Gave new names to my new key definitions; they begin with "kx"
32+ instead of "k". Also added kFWD_DELETE and kHELP
33+*/
34+
35+// LP changes:
36+#define kxESCAPE 0x35
37+#define kxDELETE 0x33
38+#define kxHELP 0x72
39+#define kxFWD_DELETE 0x75
40+#define kxHOME 0x73
41+#define kxEND 0x77
42+#define kxPAGE_UP 0x74
43+#define kxPAGE_DOWN 0x79
44+#define kxLEFT_ARROW 0x7B
45+#define kxRIGHT_ARROW 0x7C
46+#define kxUP_ARROW 0x7E
47+#define kxDOWN_ARROW 0x7D
48+
49+#define kDELETE 0x08
50+#define kHELP 0x05
51+#define kFWD_DELETE 0x7F
52+#define kHOME 0x01
53+#define kEND 0x04
54+#define kPAGE_UP 0x0B
55+#define kPAGE_DOWN 0x0C
56+#define kLEFT_ARROW 0x1C
57+#define kRIGHT_ARROW 0x1D
58+#define kUP_ARROW 0x1E
59+#define kDOWN_ARROW 0x1F
60+
61+
62+#define kcF1 0x7A
63+#define kcF2 0x78
64+#define kcF3 0x63
65+#define kcF4 0x76
66+#define kcF5 0x60
67+#define kcF6 0x61
68+#define kcF7 0x62
69+#define kcF8 0x64
70+#define kcF9 0x65
71+#define kcF10 0x6D
72+#define kcF11 0x67
73+#define kcF12 0x6F
74+// LP additions:
75+#define kcF13 0x69
76+#define kcF14 0x6B
77+#define kcF15 0x71
78+
79+#endif
--- marathon/trunk/Source_Files/CSeries/converter.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/converter.cpp (revision 522)
@@ -1,189 +1,189 @@
1-/*
2- * converter.cpp
3- * AlephOne-OSX10.4
4- *
5- * Created by 縺ソ縺。縺ゅ″ on 08/06/24.
6- * Copyright 2008 __MyCompanyName__. All rights reserved.
7- *
8- * Modified by Logue
9- */
10-
11-#include "converter.h"
12-typedef unsigned short uint16;
13-#include <string.h>
14-#include <iconv.h>
15-
16-// Convert from Shift_JIS to UTF8
17-char* sjis2utf8(const char* str, size_t len) {
18- static char text[1024];
19- static char src[1024];
20- strcpy(src, str);
21- memset(text,0,1024);
22- char* strp = src;
23- char* retp = text;
24- size_t sz = 1024;
25- iconv_t i = iconv_open("UTF-8", "SHIFT-JIS");
26- iconv_t j = iconv_open("UTF-8", "MACROMAN");
27- if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
28- strp = src;
29- retp = text;
30- sz = 1024;
31- iconv(j, &strp, &len, &retp, &sz);
32- }
33- if( text[strlen(text)-1] == 13) { text[strlen(text)-1] = 0; }
34- iconv_close(i);
35- iconv_close(j);
36- return text;
37-}
38-// Convert from UTF8 to Shift_JIS
39-char* utf82sjis(const char* str, size_t len) {
40- static char text[1024];
41- static char src[1024];
42- strcpy(src, str);
43- memset(text,0,1024);
44- char* strp = src;
45- char* retp = text;
46- size_t sz = 1024;
47- iconv_t i = iconv_open("SHIFT-JIS", "UTF-8");
48- if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
49- // SHIFT-JIS縺ォ縺ァ縺阪↑縺・→縺阪・縺昴・縺セ縺セ繧ウ繝斐・
50- strncpy(text, str, len);
51- }
52- if( text[strlen(text)-1] == 13) { text[strlen(text)-1] = 0; }
53- iconv_close(i);
54- return text;
55-}
56-#define MAC_LINE_END 13
57-// Convert from Shift_JIS to Unidode
58-// AlephOneJP overrides to process_macroman().
59-uint16* sjis2utf16(const char* str, size_t len) {
60- static char base[1024]; // in case lastn letter is MAC_LINE_END
61-
62- memset(base, 0, 1024);
63- strncpy(base, str, len);
64- if( base[len-1] == MAC_LINE_END ) {
65- base[len-1] = '\0';
66- --len;
67- }
68- static uint16 text[1024];
69- memset(text,0,2048);
70- char* strp = base;
71- char* retp = (char*)text;
72- size_t sz = 1024;
73- iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
74- iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
75- if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
76- strp = base;
77- retp = (char*)text;
78- sz = 1024;
79- iconv(j, &strp, &len, &retp, &sz);
80- }
81- iconv_close(i);
82- iconv_close(j);
83- return text;
84-}
85-
86-// Convert from UTF8 to Unidode
87-uint16* utf82utf16(const char* str, size_t len) {
88- static uint16 text[1024];
89- static char src[1024];
90- strcpy(src,str);
91- memset(text,0,2048);
92- char* strp = src;
93- char* retp = (char*)text;
94- size_t sz = 1024;
95- iconv_t i = iconv_open("UCS-2-INTERNAL", "UTF-8");
96- if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
97- }
98- iconv_close(i);
99- return text;
100-}
101-
102-// Convert from Unicode to UTF8
103-char* utf162utf8(const uint16* str, size_t len) {
104- static char text[1024];
105- static char src[1024];
106- memset(src, 0, 1024*sizeof(uint16));
107- memcpy(src, str, len*sizeof(uint16));
108- memset(text,0,1024);
109- len *= 2;
110- char* strp = src;
111- char* retp = text;
112- size_t sz = 1024;
113- iconv_t i = iconv_open("UTF-8", "UCS-2-INTERNAL");
114- if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
115- }
116- iconv_close(i);
117- return text;
118-}
119-
120-uint16 sjisChar(char* in, int* step) {
121- size_t len;
122- if( *in == 13 ) { if( step ) *step += 1; return 13; }
123- if( step ) {
124- if ( isJChar((unsigned char)*in) ) {
125- *step += 2;
126- len = 2;
127- } else {
128- *step += 1;
129- len = 1;
130- }
131- }
132- uint16 text[2];
133- memset(text,0,4);
134- char* strp = in;
135- char* retp = (char*)text;
136- size_t sz = 4;
137- iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
138- iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
139- if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
140- strp = in;
141- retp = (char*)text;
142- sz = 4;
143- iconv(j, &strp, &len, &retp, &sz);
144- }
145- iconv_close(i);
146- iconv_close(j);
147- return text[0];
148-}
149-
150-int unicodeChar( const char* input, uint16* ret) {
151- uint16 text[3];
152- static char src[1024];
153- strcpy(src,input);
154- memset(text,0,4);
155- char* strp = src;
156- char* retp = (char*)text;
157- size_t len = strlen(input), sz = 6;
158-
159- iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
160- iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
161-
162- if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
163- strp = src;
164- retp = (char*)text;
165- sz = 4;
166- iconv(j, &strp, &len, &retp, &sz);
167- }
168- iconv_close(i);
169- iconv_close(j);
170- *ret = text[0];
171-
172- unsigned char first = *input;
173- if( first < 0x80 || ( first > 0xa0 && first < 0xe0 ) ) {
174- return 1;
175- } else if( first < 0xeb ) {
176- return 2;
177- } else {
178- return 1;
179- }
180-}
181-
182-// Detect 2-byte char. (for Shift_JIS)
183-bool isJChar(unsigned char text) {
184- return (((text >= 0x81) && (text <= 0x9f)) || ((text >= 0xe0) && (text <= 0xfc))) ? true : false;
185-}
186-// Detect 2nd charactor of 2-byte char. (for Shift_JIS)
187-bool is2ndJChar(unsigned char text) {
188- return (((0x7F != text) && (0x40 <= text)) || ((text >= 0xe0) && (text <= 0xfc))) ? true : false;
189-}
1+/*
2+ * converter.cpp
3+ * AlephOne-OSX10.4
4+ *
5+ * Created by 縺ソ縺。縺ゅ″ on 08/06/24.
6+ * Copyright 2008 __MyCompanyName__. All rights reserved.
7+ *
8+ * Modified by Logue
9+ */
10+
11+#include "converter.h"
12+typedef unsigned short uint16;
13+#include <string.h>
14+#include <iconv.h>
15+
16+// Convert from Shift_JIS to UTF8
17+char* sjis2utf8(const char* str, size_t len) {
18+ static char text[1024];
19+ static char src[1024];
20+ strcpy(src, str);
21+ memset(text,0,1024);
22+ char* strp = src;
23+ char* retp = text;
24+ size_t sz = 1024;
25+ iconv_t i = iconv_open("UTF-8", "SHIFT-JIS");
26+ iconv_t j = iconv_open("UTF-8", "MACROMAN");
27+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
28+ strp = src;
29+ retp = text;
30+ sz = 1024;
31+ iconv(j, &strp, &len, &retp, &sz);
32+ }
33+ if( text[strlen(text)-1] == 13) { text[strlen(text)-1] = 0; }
34+ iconv_close(i);
35+ iconv_close(j);
36+ return text;
37+}
38+// Convert from UTF8 to Shift_JIS
39+char* utf82sjis(const char* str, size_t len) {
40+ static char text[1024];
41+ static char src[1024];
42+ strcpy(src, str);
43+ memset(text,0,1024);
44+ char* strp = src;
45+ char* retp = text;
46+ size_t sz = 1024;
47+ iconv_t i = iconv_open("SHIFT-JIS", "UTF-8");
48+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
49+ // SHIFT-JIS縺ォ縺ァ縺阪↑縺・→縺阪・縺昴・縺セ縺セ繧ウ繝斐・
50+ strncpy(text, str, len);
51+ }
52+ if( text[strlen(text)-1] == 13) { text[strlen(text)-1] = 0; }
53+ iconv_close(i);
54+ return text;
55+}
56+#define MAC_LINE_END 13
57+// Convert from Shift_JIS to Unidode
58+// AlephOneJP overrides to process_macroman().
59+uint16* sjis2utf16(const char* str, size_t len) {
60+ static char base[1024]; // in case lastn letter is MAC_LINE_END
61+
62+ memset(base, 0, 1024);
63+ strncpy(base, str, len);
64+ if( base[len-1] == MAC_LINE_END ) {
65+ base[len-1] = '\0';
66+ --len;
67+ }
68+ static uint16 text[1024];
69+ memset(text,0,2048);
70+ char* strp = base;
71+ char* retp = (char*)text;
72+ size_t sz = 1024;
73+ iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
74+ iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
75+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
76+ strp = base;
77+ retp = (char*)text;
78+ sz = 1024;
79+ iconv(j, &strp, &len, &retp, &sz);
80+ }
81+ iconv_close(i);
82+ iconv_close(j);
83+ return text;
84+}
85+
86+// Convert from UTF8 to Unidode
87+uint16* utf82utf16(const char* str, size_t len) {
88+ static uint16 text[1024];
89+ static char src[1024];
90+ strcpy(src,str);
91+ memset(text,0,2048);
92+ char* strp = src;
93+ char* retp = (char*)text;
94+ size_t sz = 1024;
95+ iconv_t i = iconv_open("UCS-2-INTERNAL", "UTF-8");
96+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
97+ }
98+ iconv_close(i);
99+ return text;
100+}
101+
102+// Convert from Unicode to UTF8
103+char* utf162utf8(const uint16* str, size_t len) {
104+ static char text[1024];
105+ static char src[1024];
106+ memset(src, 0, 1024*sizeof(uint16));
107+ memcpy(src, str, len*sizeof(uint16));
108+ memset(text,0,1024);
109+ len *= 2;
110+ char* strp = src;
111+ char* retp = text;
112+ size_t sz = 1024;
113+ iconv_t i = iconv_open("UTF-8", "UCS-2-INTERNAL");
114+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
115+ }
116+ iconv_close(i);
117+ return text;
118+}
119+
120+uint16 sjisChar(char* in, int* step) {
121+ size_t len;
122+ if( *in == 13 ) { if( step ) *step += 1; return 13; }
123+ if( step ) {
124+ if ( isJChar((unsigned char)*in) ) {
125+ *step += 2;
126+ len = 2;
127+ } else {
128+ *step += 1;
129+ len = 1;
130+ }
131+ }
132+ uint16 text[2];
133+ memset(text,0,4);
134+ char* strp = in;
135+ char* retp = (char*)text;
136+ size_t sz = 4;
137+ iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
138+ iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
139+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
140+ strp = in;
141+ retp = (char*)text;
142+ sz = 4;
143+ iconv(j, &strp, &len, &retp, &sz);
144+ }
145+ iconv_close(i);
146+ iconv_close(j);
147+ return text[0];
148+}
149+
150+int unicodeChar( const char* input, uint16* ret) {
151+ uint16 text[3];
152+ static char src[1024];
153+ strcpy(src,input);
154+ memset(text,0,4);
155+ char* strp = src;
156+ char* retp = (char*)text;
157+ size_t len = strlen(input), sz = 6;
158+
159+ iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
160+ iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
161+
162+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
163+ strp = src;
164+ retp = (char*)text;
165+ sz = 4;
166+ iconv(j, &strp, &len, &retp, &sz);
167+ }
168+ iconv_close(i);
169+ iconv_close(j);
170+ *ret = text[0];
171+
172+ unsigned char first = *input;
173+ if( first < 0x80 || ( first > 0xa0 && first < 0xe0 ) ) {
174+ return 1;
175+ } else if( first < 0xeb ) {
176+ return 2;
177+ } else {
178+ return 1;
179+ }
180+}
181+
182+// Detect 2-byte char. (for Shift_JIS)
183+bool isJChar(unsigned char text) {
184+ return (((text >= 0x81) && (text <= 0x9f)) || ((text >= 0xe0) && (text <= 0xfc))) ? true : false;
185+}
186+// Detect 2nd charactor of 2-byte char. (for Shift_JIS)
187+bool is2ndJChar(unsigned char text) {
188+ return (((0x7F != text) && (0x40 <= text)) || ((text >= 0xe0) && (text <= 0xfc))) ? true : false;
189+}
--- marathon/trunk/Source_Files/CSeries/FilmProfile.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/FilmProfile.cpp (revision 522)
@@ -18,6 +18,7 @@
1818 false, // infinity_tag_fix
1919 false, // adjacent_polygons_always_intersect
2020 true, // early_object_initialization
21+ true, // reset_action_queues
2122 };
2223
2324 static FilmProfile marathon2 = {
@@ -36,6 +37,7 @@
3637 false, // infinity_tag_fix
3738 false, // adjacent_polygons_always_intersect
3839 false, // early_object_initialization
40+ false, // reset_action_queues
3941 };
4042
4143 static FilmProfile marathon_infinity = {
@@ -54,6 +56,7 @@
5456 true, // infinity_tag_fix
5557 true, // adjacent_polygons_always_intersect
5658 false, // early_object_initialization
59+ false, // reset_action_queues
5760 };
5861
5962 FilmProfile film_profile = alephone1_0;
--- marathon/trunk/Source_Files/CSeries/snprintf.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/snprintf.h (revision 522)
@@ -1,44 +1,44 @@
1-/*
2- * snprintf.h - crude, unsafe imitation of the real snprintf() and vsnprintf()
3-
4- Copyright (C) 2003 and beyond by Woody Zenfell, III
5- and the "Aleph One" developers.
6-
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 3 of the License, or
10- (at your option) any later version.
11-
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.
16-
17- This license is contained in the file "COPYING",
18- which is included with this source code; it is available online at
19- http://www.gnu.org/licenses/gpl.html
20-
21-
22- Jan. 17, 2003 (Woody Zenfell): Created.
23-
24-*/
25-
26-#ifndef SNPRINTF_H
27-#define SNPRINTF_H
28-
29-#include <stdarg.h>
30-#include <streambuf> // Fix MSVC7 strangeness
31-
32-#ifdef HAVE_CONFIG_H
33-#include "config.h"
34-#endif
35-
36-#ifndef HAVE_SNPRINTF
37-extern int snprintf(char* inBuffer, size_t inBufferSize, const char* inFormat, ...);
38-#endif
39-
40-#ifndef HAVE_VSNPRINTF
41-extern int vsnprintf(char* inBuffer, size_t inBufferSize, const char* inFormat, va_list inArgs);
42-#endif
43-
44-#endif // SNPRINTF_H
1+/*
2+ * snprintf.h - crude, unsafe imitation of the real snprintf() and vsnprintf()
3+
4+ Copyright (C) 2003 and beyond by Woody Zenfell, III
5+ and the "Aleph One" developers.
6+
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 3 of the License, or
10+ (at your option) any later version.
11+
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.
16+
17+ This license is contained in the file "COPYING",
18+ which is included with this source code; it is available online at
19+ http://www.gnu.org/licenses/gpl.html
20+
21+
22+ Jan. 17, 2003 (Woody Zenfell): Created.
23+
24+*/
25+
26+#ifndef SNPRINTF_H
27+#define SNPRINTF_H
28+
29+#include <stdarg.h>
30+#include <streambuf> // Fix MSVC7 strangeness
31+
32+#ifdef HAVE_CONFIG_H
33+#include "config.h"
34+#endif
35+
36+#ifndef HAVE_SNPRINTF
37+extern int snprintf(char* inBuffer, size_t inBufferSize, const char* inFormat, ...);
38+#endif
39+
40+#ifndef HAVE_VSNPRINTF
41+extern int vsnprintf(char* inBuffer, size_t inBufferSize, const char* inFormat, va_list inArgs);
42+#endif
43+
44+#endif // SNPRINTF_H
--- marathon/trunk/Source_Files/CSeries/csdialogs_sdl.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/csdialogs_sdl.cpp (revision 522)
@@ -1,416 +1,416 @@
1-/*
2- * csdialogs_sdl.cpp
3-
4- Copyright (C) 2001 and beyond by Woody Zenfell, III
5- and the "Aleph One" developers.
6-
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 3 of the License, or
10- (at your option) any later version.
11-
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.
16-
17- This license is contained in the file "COPYING",
18- which is included with this source code; it is available online at
19- http://www.gnu.org/licenses/gpl.html
20-
21- * The purpose of this file is to provide a few easy-to-implement dialog-item
22- * modification and query functions, for greater source compatibility between
23- * SDL and traditional Mac versions.
24- *
25- * Created by woody on Wed Sep 19 2001.
26- */
27-
28-#include "cseries.h"
29-#include "sdl_dialogs.h"
30-#include "sdl_widgets.h"
31-
32-// These fail silently, as half the existing calls to them are for widgets we don't use.
33-// Note that we merely disable/enable the items... this has semantic disagreement with the Mac
34-// version beyond "the user can see controls that have been hidden", though: if a control were
35-// enabled while hidden, or disabled and then shown, the user would be allowed to interact with
36-// the control in our version, but would not be able to on the Mac side. Fortunately, I think
37-// the current code does not contain those usage patterns.
38-void HideDialogItem(DialogPtr dialog, short item_index) {
39- widget* theWidget = dialog->get_widget_by_id(item_index);
40- if(theWidget != NULL)
41- theWidget->set_enabled(false);
42-}
43-
44-void ShowDialogItem(DialogPtr dialog, short item_index) {
45- widget* theWidget = dialog->get_widget_by_id(item_index);
46- if(theWidget != NULL)
47- theWidget->set_enabled(true);
48-}
49-
50-
51-
52-// Item must be a w_number_entry.
53-int32
54-extract_number_from_text_item(
55- DialogPtr dlg,
56- short item) {
57-
58- assert(dlg != NULL);
59-
60- w_number_entry* theWidget = dynamic_cast<w_number_entry*>(dlg->get_widget_by_id(item));
61-
62- assert(theWidget != NULL);
63-
64- return theWidget->get_number();
65-}
66-
67-
68-// Item must be a w_number_entry.
69-void
70-insert_number_into_text_item(
71- DialogPtr dlg,
72- short item,
73- int32 number) {
74-
75- assert(dlg != NULL);
76-
77- w_number_entry* theWidget = dynamic_cast<w_number_entry*>(dlg->get_widget_by_id(item));
78-
79- assert(theWidget != NULL);
80-
81- theWidget->set_number(number);
82-}
83-
84-
85-// For enable/disable, widget may be anything - but see modify_control_enabled if that's all you're trying to do.
86-// For change value, widget must be a w_select (or subclass, but should not be a w_toggle due to different numbering scheme).
87-// (See modify_boolean_control if you're operating on a w_toggle.)
88-void
89-modify_selection_control(
90- DialogPtr inDialog,
91- short inWhichItem,
92- short inChangeEnable,
93- short inChangeValue) {
94-
95- assert(inDialog != NULL);
96-
97- widget* theWidget = inDialog->get_widget_by_id(inWhichItem);
98-
99- assert(theWidget != NULL);
100-
101- if(inChangeEnable != NONE)
102- theWidget->set_enabled(inChangeEnable == CONTROL_ACTIVE ? true : false);
103-
104- if(inChangeValue != NONE) {
105- w_select* theSelectionWidget = dynamic_cast<w_select*>(theWidget);
106- assert(theSelectionWidget != NULL);
107-
108- theSelectionWidget->set_selection(inChangeValue - 1);
109- }
110-}
111-
112-
113-
114-void
115-modify_control_enabled(
116- DialogPtr inDialog,
117- short inWhichItem,
118- short inChangeEnable) {
119-
120- assert(inDialog != NULL);
121-
122- widget* theWidget = inDialog->get_widget_by_id(inWhichItem);
123-
124- assert(theWidget != NULL);
125-
126- if(inChangeEnable != NONE)
127- theWidget->set_enabled(inChangeEnable == CONTROL_ACTIVE ? true : false);
128-}
129-
130-
131-
132-void
133-modify_boolean_control(
134- DialogPtr inDialog,
135- short inWhichItem,
136- short inChangeEnable,
137- short inChangeValue) {
138-
139- assert(inDialog != NULL);
140-
141- widget* theWidget = inDialog->get_widget_by_id(inWhichItem);
142-
143- assert(theWidget != NULL);
144-
145- if(inChangeEnable != NONE)
146- theWidget->set_enabled(inChangeEnable == CONTROL_ACTIVE ? true : false);
147-
148- if(inChangeValue != NONE) {
149- w_toggle* theSelectionWidget = dynamic_cast<w_toggle*>(theWidget);
150- assert(theSelectionWidget != NULL);
151-
152- theSelectionWidget->set_selection(inChangeValue);
153- }
154-}
155-
156-
157-
158-/*************************************************************************************************
159- *
160- * Function: get_selection_control_value
161- * Purpose: given a dialog and an item number, extract the value of the control
162- *
163- *************************************************************************************************/
164-// Works only on w_select (and subclasses).
165-short
166-get_selection_control_value(DialogPtr dialog, short which_control)
167-{
168- assert(dialog != NULL);
169-
170- w_select* theSelectionWidget = dynamic_cast<w_select*>(dialog->get_widget_by_id(which_control));
171-
172- assert(theSelectionWidget != NULL);
173-
174- return theSelectionWidget->get_selection() + 1;
175-}
176-
177-
178-
179-// Just the same, but for w_toggles.
180-bool
181-get_boolean_control_value(DialogPtr dialog, short which_control)
182-{
183- assert(dialog != NULL);
184-
185- w_toggle* theSelectionWidget = dynamic_cast<w_toggle*>(dialog->get_widget_by_id(which_control));
186-
187- assert(theSelectionWidget != NULL);
188-
189- return theSelectionWidget->get_selection();
190-}
191-
192-
193-
194-void
195-copy_pstring_from_text_field(DialogPtr dialog, short item, unsigned char* pstring) {
196- assert(dialog != NULL);
197-
198- w_text_entry* theTextField = dynamic_cast<w_text_entry*>(dialog->get_widget_by_id(item));
199-
200- assert(theTextField != NULL);
201-
202- const char* source = theTextField->get_text();
203- char* dest = (char*) pstring;
204-
205- // pstring buffer is probably not going to be bigger than 256 bytes since that's max length of a pstr.
206- if(strlen(source) > 255)
207- strncpy(dest, source, 255); // (leave room for terminating NULL)
208- // OTOH don't want to fill all 256 memory locations (strncpy pads with '\0') if, say, caller only has 32 bytes for us...
209- else
210- strcpy(dest, source);
211-
212- // in-place conversion
213- a1_c2pstr(dest);
214-}
215-
216-
217-
218-void
219-copy_pstring_to_text_field(DialogPtr dialog, short item, const unsigned char* pstring) {
220- assert(dialog != NULL);
221-
222- w_text_entry* theTextField = dynamic_cast<w_text_entry*>(dialog->get_widget_by_id(item));
223-
224- assert(theTextField != NULL);
225-
226- unsigned char* source = pstrdup(pstring);
227- char* string = a1_p2cstr(source);
228-
229- theTextField->set_text(string);
230-
231- free(source);
232-}
233-
234-
235-
236-void
237-copy_pstring_to_static_text(DialogPtr dialog, short item, const unsigned char* pstring) {
238- assert(dialog != NULL);
239-
240- w_static_text* theStaticText = dynamic_cast<w_static_text*>(dialog->get_widget_by_id(item));
241-
242- assert(theStaticText != NULL);
243-
244- unsigned char* source = pstrdup(pstring);
245- char* string = a1_p2cstr(source);
246-
247- theStaticText->set_text(string);
248-
249- free(source);
250-}
251-
252-
253-bool QQ_control_exists (DialogPTR dlg, int item)
254-{
255- return (dlg->get_widget_by_id(item) != NULL);
256-}
257-
258-// Can't hide SDL widgets, so we'll deactivate them instead.
259-extern void QQ_hide_control (DialogPTR dlg, int item)
260-{
261- QQ_set_control_activity (dlg, item, false);
262-}
263-
264-extern void QQ_show_control (DialogPTR dlg, int item)
265-{
266- QQ_set_control_activity (dlg, item, true);
267-}
268-
269-bool QQ_get_boolean_control_value (DialogPTR dlg, int item)
270-{
271- assert(dlg != NULL);
272- w_toggle* theWidget = dynamic_cast<w_toggle*>(dlg->get_widget_by_id(item));
273- if (theWidget == NULL) {
274- return false;
275- } else {
276- return theWidget->get_selection();
277- }
278-}
279-
280-void QQ_set_boolean_control_value (DialogPTR dlg, int item, bool value)
281-{
282- assert(dlg != NULL);
283- w_toggle* theWidget = dynamic_cast<w_toggle*>(dlg->get_widget_by_id(item));
284- if (theWidget != NULL) {
285- theWidget->set_selection(value ? 1 : 0);
286- }
287-}
288-
289-int QQ_get_selector_control_value (DialogPTR dlg, int item)
290-{
291- assert(dlg != NULL);
292-
293- w_select* theWidget = dynamic_cast<w_select*>(dlg->get_widget_by_id(item));
294- if (theWidget != NULL)
295- return theWidget->get_selection();
296-
297- w_select_popup* theWidget2 = dynamic_cast<w_select_popup*>(dlg->get_widget_by_id(item));
298- if (theWidget2 != NULL)
299- return theWidget2->get_selection();
300-
301- return 0;
302-}
303-
304-void QQ_set_selector_control_value (DialogPTR dlg, int item, int value)
305-{
306- assert(dlg != NULL);
307-
308- w_select* theWidget = dynamic_cast<w_select*>(dlg->get_widget_by_id(item));
309- if (theWidget != NULL) {
310- theWidget->set_selection(value);
311- }
312-
313- w_select_popup* theWidget2 = dynamic_cast<w_select_popup*>(dlg->get_widget_by_id(item));
314- if (theWidget2 != NULL) {
315- theWidget2->set_selection(value);
316- }
317-}
318-
319-void QQ_set_selector_control_labels (DialogPTR dlg, int item, const std::vector<std::string> labels)
320-{
321- assert(dlg != NULL);
322-
323- w_select_popup* theWidget = dynamic_cast<w_select_popup*>(dlg->get_widget_by_id(item));
324- if (theWidget != NULL) {
325- theWidget->set_labels(labels);
326- }
327-}
328-
329-void QQ_set_selector_control_labels_from_stringset (DialogPTR dlg, int item, int stringset_id)
330-{
331- assert(dlg != NULL);
332-
333- w_select_popup* theWidget = dynamic_cast<w_select_popup*>(dlg->get_widget_by_id(item));
334- if (theWidget != NULL) {
335- theWidget->set_labels(build_stringvector_from_stringset (stringset_id));
336- }
337-
338- w_select* theWidget2 = dynamic_cast<w_select*>(dlg->get_widget_by_id(item));
339- if (theWidget2 != NULL) {
340- theWidget2->set_labels_stringset(stringset_id);
341- }
342-}
343-
344-const std::string QQ_copy_string_from_text_control (DialogPTR dlg, int item)
345-{
346- assert (dlg != NULL);
347-
348- widget* theWidget = dlg->get_widget_by_id(item);
349- if (theWidget == NULL)
350- return string();
351-
352- w_text_entry* theTextEntryWidget = dynamic_cast<w_text_entry*>(dlg->get_widget_by_id(item));
353- if (theTextEntryWidget != NULL) {
354- return string(theTextEntryWidget->get_text());
355- }
356-
357- return string();
358-}
359-
360-void QQ_copy_string_to_text_control (DialogPTR dlg, int item, const std::string &s)
361-{
362- assert (dlg != NULL);
363-
364- widget* theWidget = dlg->get_widget_by_id(item);
365- if (theWidget == NULL)
366- return;
367-
368- w_text_entry* theTextEntryWidget = dynamic_cast<w_text_entry*>(theWidget);
369- if (theTextEntryWidget != NULL) {
370- theTextEntryWidget->set_text(s.c_str());
371- return;
372- }
373-
374- w_static_text* theStaticTextWidget = dynamic_cast<w_static_text*>(theWidget);
375- if (theStaticTextWidget != NULL) {
376- theStaticTextWidget->set_text(s.c_str());
377- return;
378- }
379-
380- return;
381-}
382-
383-void QQ_set_control_activity (DialogPTR dlg, int item, bool active)
384-{
385- assert(dlg != NULL);
386-
387- widget* theWidget = dlg->get_widget_by_id(item);
388- if (theWidget == NULL)
389- return;
390-
391- theWidget->set_enabled (active);
392-}
393-
394-extern int32 QQ_extract_number_from_text_control (DialogPTR dlg, int item)
395-{
396- assert(dlg != NULL);
397-
398- w_number_entry* theWidget = dynamic_cast<w_number_entry*>(dlg->get_widget_by_id(item));
399-
400- if (theWidget == NULL)
401- return 0;
402-
403- return theWidget->get_number();
404-}
405-
406-extern void QQ_insert_number_into_text_control (DialogPTR dlg, int item, int32 number)
407-{
408- assert(dlg != NULL);
409-
410- w_number_entry* theWidget = dynamic_cast<w_number_entry*>(dlg->get_widget_by_id(item));
411-
412- if(theWidget == NULL)
413- return;
414-
415- theWidget->set_number(number);
416-}
1+/*
2+ * csdialogs_sdl.cpp
3+
4+ Copyright (C) 2001 and beyond by Woody Zenfell, III
5+ and the "Aleph One" developers.
6+
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 3 of the License, or
10+ (at your option) any later version.
11+
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.
16+
17+ This license is contained in the file "COPYING",
18+ which is included with this source code; it is available online at
19+ http://www.gnu.org/licenses/gpl.html
20+
21+ * The purpose of this file is to provide a few easy-to-implement dialog-item
22+ * modification and query functions, for greater source compatibility between
23+ * SDL and traditional Mac versions.
24+ *
25+ * Created by woody on Wed Sep 19 2001.
26+ */
27+
28+#include "cseries.h"
29+#include "sdl_dialogs.h"
30+#include "sdl_widgets.h"
31+
32+// These fail silently, as half the existing calls to them are for widgets we don't use.
33+// Note that we merely disable/enable the items... this has semantic disagreement with the Mac
34+// version beyond "the user can see controls that have been hidden", though: if a control were
35+// enabled while hidden, or disabled and then shown, the user would be allowed to interact with
36+// the control in our version, but would not be able to on the Mac side. Fortunately, I think
37+// the current code does not contain those usage patterns.
38+void HideDialogItem(DialogPtr dialog, short item_index) {
39+ widget* theWidget = dialog->get_widget_by_id(item_index);
40+ if(theWidget != NULL)
41+ theWidget->set_enabled(false);
42+}
43+
44+void ShowDialogItem(DialogPtr dialog, short item_index) {
45+ widget* theWidget = dialog->get_widget_by_id(item_index);
46+ if(theWidget != NULL)
47+ theWidget->set_enabled(true);
48+}
49+
50+
51+
52+// Item must be a w_number_entry.
53+int32
54+extract_number_from_text_item(
55+ DialogPtr dlg,
56+ short item) {
57+
58+ assert(dlg != NULL);
59+
60+ w_number_entry* theWidget = dynamic_cast<w_number_entry*>(dlg->get_widget_by_id(item));
61+
62+ assert(theWidget != NULL);
63+
64+ return theWidget->get_number();
65+}
66+
67+
68+// Item must be a w_number_entry.
69+void
70+insert_number_into_text_item(
71+ DialogPtr dlg,
72+ short item,
73+ int32 number) {
74+
75+ assert(dlg != NULL);
76+
77+ w_number_entry* theWidget = dynamic_cast<w_number_entry*>(dlg->get_widget_by_id(item));
78+
79+ assert(theWidget != NULL);
80+
81+ theWidget->set_number(number);
82+}
83+
84+
85+// For enable/disable, widget may be anything - but see modify_control_enabled if that's all you're trying to do.
86+// For change value, widget must be a w_select (or subclass, but should not be a w_toggle due to different numbering scheme).
87+// (See modify_boolean_control if you're operating on a w_toggle.)
88+void
89+modify_selection_control(
90+ DialogPtr inDialog,
91+ short inWhichItem,
92+ short inChangeEnable,
93+ short inChangeValue) {
94+
95+ assert(inDialog != NULL);
96+
97+ widget* theWidget = inDialog->get_widget_by_id(inWhichItem);
98+
99+ assert(theWidget != NULL);
100+
101+ if(inChangeEnable != NONE)
102+ theWidget->set_enabled(inChangeEnable == CONTROL_ACTIVE ? true : false);
103+
104+ if(inChangeValue != NONE) {
105+ w_select* theSelectionWidget = dynamic_cast<w_select*>(theWidget);
106+ assert(theSelectionWidget != NULL);
107+
108+ theSelectionWidget->set_selection(inChangeValue - 1);
109+ }
110+}
111+
112+
113+
114+void
115+modify_control_enabled(
116+ DialogPtr inDialog,
117+ short inWhichItem,
118+ short inChangeEnable) {
119+
120+ assert(inDialog != NULL);
121+
122+ widget* theWidget = inDialog->get_widget_by_id(inWhichItem);
123+
124+ assert(theWidget != NULL);
125+
126+ if(inChangeEnable != NONE)
127+ theWidget->set_enabled(inChangeEnable == CONTROL_ACTIVE ? true : false);
128+}
129+
130+
131+
132+void
133+modify_boolean_control(
134+ DialogPtr inDialog,
135+ short inWhichItem,
136+ short inChangeEnable,
137+ short inChangeValue) {
138+
139+ assert(inDialog != NULL);
140+
141+ widget* theWidget = inDialog->get_widget_by_id(inWhichItem);
142+
143+ assert(theWidget != NULL);
144+
145+ if(inChangeEnable != NONE)
146+ theWidget->set_enabled(inChangeEnable == CONTROL_ACTIVE ? true : false);
147+
148+ if(inChangeValue != NONE) {
149+ w_toggle* theSelectionWidget = dynamic_cast<w_toggle*>(theWidget);
150+ assert(theSelectionWidget != NULL);
151+
152+ theSelectionWidget->set_selection(inChangeValue);
153+ }
154+}
155+
156+
157+
158+/*************************************************************************************************
159+ *
160+ * Function: get_selection_control_value
161+ * Purpose: given a dialog and an item number, extract the value of the control
162+ *
163+ *************************************************************************************************/
164+// Works only on w_select (and subclasses).
165+short
166+get_selection_control_value(DialogPtr dialog, short which_control)
167+{
168+ assert(dialog != NULL);
169+
170+ w_select* theSelectionWidget = dynamic_cast<w_select*>(dialog->get_widget_by_id(which_control));
171+
172+ assert(theSelectionWidget != NULL);
173+
174+ return theSelectionWidget->get_selection() + 1;
175+}
176+
177+
178+
179+// Just the same, but for w_toggles.
180+bool
181+get_boolean_control_value(DialogPtr dialog, short which_control)
182+{
183+ assert(dialog != NULL);
184+
185+ w_toggle* theSelectionWidget = dynamic_cast<w_toggle*>(dialog->get_widget_by_id(which_control));
186+
187+ assert(theSelectionWidget != NULL);
188+
189+ return theSelectionWidget->get_selection();
190+}
191+
192+
193+
194+void
195+copy_pstring_from_text_field(DialogPtr dialog, short item, unsigned char* pstring) {
196+ assert(dialog != NULL);
197+
198+ w_text_entry* theTextField = dynamic_cast<w_text_entry*>(dialog->get_widget_by_id(item));
199+
200+ assert(theTextField != NULL);
201+
202+ const char* source = theTextField->get_text();
203+ char* dest = (char*) pstring;
204+
205+ // pstring buffer is probably not going to be bigger than 256 bytes since that's max length of a pstr.
206+ if(strlen(source) > 255)
207+ strncpy(dest, source, 255); // (leave room for terminating NULL)
208+ // OTOH don't want to fill all 256 memory locations (strncpy pads with '\0') if, say, caller only has 32 bytes for us...
209+ else
210+ strcpy(dest, source);
211+
212+ // in-place conversion
213+ a1_c2pstr(dest);
214+}
215+
216+
217+
218+void
219+copy_pstring_to_text_field(DialogPtr dialog, short item, const unsigned char* pstring) {
220+ assert(dialog != NULL);
221+
222+ w_text_entry* theTextField = dynamic_cast<w_text_entry*>(dialog->get_widget_by_id(item));
223+
224+ assert(theTextField != NULL);
225+
226+ unsigned char* source = pstrdup(pstring);
227+ char* string = a1_p2cstr(source);
228+
229+ theTextField->set_text(string);
230+
231+ free(source);
232+}
233+
234+
235+
236+void
237+copy_pstring_to_static_text(DialogPtr dialog, short item, const unsigned char* pstring) {
238+ assert(dialog != NULL);
239+
240+ w_static_text* theStaticText = dynamic_cast<w_static_text*>(dialog->get_widget_by_id(item));
241+
242+ assert(theStaticText != NULL);
243+
244+ unsigned char* source = pstrdup(pstring);
245+ char* string = a1_p2cstr(source);
246+
247+ theStaticText->set_text(string);
248+
249+ free(source);
250+}
251+
252+
253+bool QQ_control_exists (DialogPTR dlg, int item)
254+{
255+ return (dlg->get_widget_by_id(item) != NULL);
256+}
257+
258+// Can't hide SDL widgets, so we'll deactivate them instead.
259+extern void QQ_hide_control (DialogPTR dlg, int item)
260+{
261+ QQ_set_control_activity (dlg, item, false);
262+}
263+
264+extern void QQ_show_control (DialogPTR dlg, int item)
265+{
266+ QQ_set_control_activity (dlg, item, true);
267+}
268+
269+bool QQ_get_boolean_control_value (DialogPTR dlg, int item)
270+{
271+ assert(dlg != NULL);
272+ w_toggle* theWidget = dynamic_cast<w_toggle*>(dlg->get_widget_by_id(item));
273+ if (theWidget == NULL) {
274+ return false;
275+ } else {
276+ return theWidget->get_selection();
277+ }
278+}
279+
280+void QQ_set_boolean_control_value (DialogPTR dlg, int item, bool value)
281+{
282+ assert(dlg != NULL);
283+ w_toggle* theWidget = dynamic_cast<w_toggle*>(dlg->get_widget_by_id(item));
284+ if (theWidget != NULL) {
285+ theWidget->set_selection(value ? 1 : 0);
286+ }
287+}
288+
289+int QQ_get_selector_control_value (DialogPTR dlg, int item)
290+{
291+ assert(dlg != NULL);
292+
293+ w_select* theWidget = dynamic_cast<w_select*>(dlg->get_widget_by_id(item));
294+ if (theWidget != NULL)
295+ return theWidget->get_selection();
296+
297+ w_select_popup* theWidget2 = dynamic_cast<w_select_popup*>(dlg->get_widget_by_id(item));
298+ if (theWidget2 != NULL)
299+ return theWidget2->get_selection();
300+
301+ return 0;
302+}
303+
304+void QQ_set_selector_control_value (DialogPTR dlg, int item, int value)
305+{
306+ assert(dlg != NULL);
307+
308+ w_select* theWidget = dynamic_cast<w_select*>(dlg->get_widget_by_id(item));
309+ if (theWidget != NULL) {
310+ theWidget->set_selection(value);
311+ }
312+
313+ w_select_popup* theWidget2 = dynamic_cast<w_select_popup*>(dlg->get_widget_by_id(item));
314+ if (theWidget2 != NULL) {
315+ theWidget2->set_selection(value);
316+ }
317+}
318+
319+void QQ_set_selector_control_labels (DialogPTR dlg, int item, const std::vector<std::string> labels)
320+{
321+ assert(dlg != NULL);
322+
323+ w_select_popup* theWidget = dynamic_cast<w_select_popup*>(dlg->get_widget_by_id(item));
324+ if (theWidget != NULL) {
325+ theWidget->set_labels(labels);
326+ }
327+}
328+
329+void QQ_set_selector_control_labels_from_stringset (DialogPTR dlg, int item, int stringset_id)
330+{
331+ assert(dlg != NULL);
332+
333+ w_select_popup* theWidget = dynamic_cast<w_select_popup*>(dlg->get_widget_by_id(item));
334+ if (theWidget != NULL) {
335+ theWidget->set_labels(build_stringvector_from_stringset (stringset_id));
336+ }
337+
338+ w_select* theWidget2 = dynamic_cast<w_select*>(dlg->get_widget_by_id(item));
339+ if (theWidget2 != NULL) {
340+ theWidget2->set_labels_stringset(stringset_id);
341+ }
342+}
343+
344+const std::string QQ_copy_string_from_text_control (DialogPTR dlg, int item)
345+{
346+ assert (dlg != NULL);
347+
348+ widget* theWidget = dlg->get_widget_by_id(item);
349+ if (theWidget == NULL)
350+ return string();
351+
352+ w_text_entry* theTextEntryWidget = dynamic_cast<w_text_entry*>(dlg->get_widget_by_id(item));
353+ if (theTextEntryWidget != NULL) {
354+ return string(theTextEntryWidget->get_text());
355+ }
356+
357+ return string();
358+}
359+
360+void QQ_copy_string_to_text_control (DialogPTR dlg, int item, const std::string &s)
361+{
362+ assert (dlg != NULL);
363+
364+ widget* theWidget = dlg->get_widget_by_id(item);
365+ if (theWidget == NULL)
366+ return;
367+
368+ w_text_entry* theTextEntryWidget = dynamic_cast<w_text_entry*>(theWidget);
369+ if (theTextEntryWidget != NULL) {
370+ theTextEntryWidget->set_text(s.c_str());
371+ return;
372+ }
373+
374+ w_static_text* theStaticTextWidget = dynamic_cast<w_static_text*>(theWidget);
375+ if (theStaticTextWidget != NULL) {
376+ theStaticTextWidget->set_text(s.c_str());
377+ return;
378+ }
379+
380+ return;
381+}
382+
383+void QQ_set_control_activity (DialogPTR dlg, int item, bool active)
384+{
385+ assert(dlg != NULL);
386+
387+ widget* theWidget = dlg->get_widget_by_id(item);
388+ if (theWidget == NULL)
389+ return;
390+
391+ theWidget->set_enabled (active);
392+}
393+
394+extern int32 QQ_extract_number_from_text_control (DialogPTR dlg, int item)
395+{
396+ assert(dlg != NULL);
397+
398+ w_number_entry* theWidget = dynamic_cast<w_number_entry*>(dlg->get_widget_by_id(item));
399+
400+ if (theWidget == NULL)
401+ return 0;
402+
403+ return theWidget->get_number();
404+}
405+
406+extern void QQ_insert_number_into_text_control (DialogPTR dlg, int item, int32 number)
407+{
408+ assert(dlg != NULL);
409+
410+ w_number_entry* theWidget = dynamic_cast<w_number_entry*>(dlg->get_widget_by_id(item));
411+
412+ if(theWidget == NULL)
413+ return;
414+
415+ theWidget->set_number(number);
416+}
--- marathon/trunk/Source_Files/CSeries/byte_swapping.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/byte_swapping.h (revision 522)
@@ -1,42 +1,42 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-#ifndef _BYTE_SWAPPING_
22-#define _BYTE_SWAPPING_
23-
24-typedef short _bs_field;
25-
26-enum {
27- _2byte = -2,
28- _4byte = -4
29-};
30-
31-#include <stddef.h>
32-
33-extern void byte_swap_memory(
34- void *memory,
35- _bs_field type,
36- int fieldcount);
37-
38-#ifndef ALEPHONE_LITTLE_ENDIAN
39-#define byte_swap_memory(memory,type,elcount) ((void)0)
40-#endif
41-
42-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+#ifndef _BYTE_SWAPPING_
22+#define _BYTE_SWAPPING_
23+
24+typedef short _bs_field;
25+
26+enum {
27+ _2byte = -2,
28+ _4byte = -4
29+};
30+
31+#include <stddef.h>
32+
33+extern void byte_swap_memory(
34+ void *memory,
35+ _bs_field type,
36+ int fieldcount);
37+
38+#ifndef ALEPHONE_LITTLE_ENDIAN
39+#define byte_swap_memory(memory,type,elcount) ((void)0)
40+#endif
41+
42+#endif
--- marathon/trunk/Source_Files/CSeries/cscluts.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/cscluts.cpp (revision 522)
@@ -1,106 +1,106 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-Jan 25, 2002 (Br'fin (Jeremy Parsons)):
21- Added TARGET_API_MAC_CARBON for Carbon.h
22-*/
23-
24-#include <stddef.h>
25-
26-#if defined(EXPLICIT_CARBON_HEADER)
27- #include <Carbon/Carbon.h>
28-/*
29-#else
30-#include <Quickdraw.h>
31-#include <Memory.h>
32-*/
33-#endif
34-
35-#include "cscluts.h"
36-#include "FileHandler.h"
37-
38-RGBColor rgb_black={0x0000,0x0000,0x0000};
39-RGBColor rgb_white={0xFFFF,0xFFFF,0xFFFF};
40-
41-RGBColor system_colors[NUM_SYSTEM_COLORS] =
42-{
43- {0x2666,0x2666,0x2666},
44- {0xD999,0xD999,0xD999}
45-};
46-
47-CTabHandle build_macintosh_color_table(
48- color_table *table)
49-{
50- CTabHandle clut;
51- int i,n;
52- rgb_color *src;
53- ColorSpec *dst;
54-
55- n=table->color_count;
56- if (n<0) {
57- n=0;
58- } else if (n>256) {
59- n=256;
60- }
61- clut=(CTabHandle)NewHandleClear(offsetof(ColorTable,ctTable)+n*sizeof (ColorSpec));
62- if (clut) {
63- (*clut)->ctSeed=GetCTSeed();
64- (*clut)->ctSize=n-1;
65-
66- src=table->colors;
67- dst=(*clut)->ctTable;
68- for (i=0; i<n; i++) {
69- dst->value=i;
70- dst->rgb.red=src->red;
71- dst->rgb.green=src->green;
72- dst->rgb.blue=src->blue;
73- src++;
74- dst++;
75- }
76- }
77- return clut;
78-}
79-
80-void build_color_table(
81- color_table *table,
82- LoadedResource& clut_rsrc)
83-{
84- int i,n;
85- ColorSpec *src;
86- rgb_color *dst;
87-
88- CTabHandle clut = CTabHandle(clut_rsrc.GetHandle());
89-
90- n=(*clut)->ctSize+1;
91- if (n<0) {
92- n=0;
93- } else if (n>256) {
94- n=256;
95- }
96- table->color_count=n;
97- src=(*clut)->ctTable;
98- dst=table->colors;
99- for (i=0; i<n; i++) {
100- dst->red=src->rgb.red;
101- dst->green=src->rgb.green;
102- dst->blue=src->rgb.blue;
103- src++;
104- dst++;
105- }
106-}
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+Jan 25, 2002 (Br'fin (Jeremy Parsons)):
21+ Added TARGET_API_MAC_CARBON for Carbon.h
22+*/
23+
24+#include <stddef.h>
25+
26+#if defined(EXPLICIT_CARBON_HEADER)
27+ #include <Carbon/Carbon.h>
28+/*
29+#else
30+#include <Quickdraw.h>
31+#include <Memory.h>
32+*/
33+#endif
34+
35+#include "cscluts.h"
36+#include "FileHandler.h"
37+
38+RGBColor rgb_black={0x0000,0x0000,0x0000};
39+RGBColor rgb_white={0xFFFF,0xFFFF,0xFFFF};
40+
41+RGBColor system_colors[NUM_SYSTEM_COLORS] =
42+{
43+ {0x2666,0x2666,0x2666},
44+ {0xD999,0xD999,0xD999}
45+};
46+
47+CTabHandle build_macintosh_color_table(
48+ color_table *table)
49+{
50+ CTabHandle clut;
51+ int i,n;
52+ rgb_color *src;
53+ ColorSpec *dst;
54+
55+ n=table->color_count;
56+ if (n<0) {
57+ n=0;
58+ } else if (n>256) {
59+ n=256;
60+ }
61+ clut=(CTabHandle)NewHandleClear(offsetof(ColorTable,ctTable)+n*sizeof (ColorSpec));
62+ if (clut) {
63+ (*clut)->ctSeed=GetCTSeed();
64+ (*clut)->ctSize=n-1;
65+
66+ src=table->colors;
67+ dst=(*clut)->ctTable;
68+ for (i=0; i<n; i++) {
69+ dst->value=i;
70+ dst->rgb.red=src->red;
71+ dst->rgb.green=src->green;
72+ dst->rgb.blue=src->blue;
73+ src++;
74+ dst++;
75+ }
76+ }
77+ return clut;
78+}
79+
80+void build_color_table(
81+ color_table *table,
82+ LoadedResource& clut_rsrc)
83+{
84+ int i,n;
85+ ColorSpec *src;
86+ rgb_color *dst;
87+
88+ CTabHandle clut = CTabHandle(clut_rsrc.GetHandle());
89+
90+ n=(*clut)->ctSize+1;
91+ if (n<0) {
92+ n=0;
93+ } else if (n>256) {
94+ n=256;
95+ }
96+ table->color_count=n;
97+ src=(*clut)->ctTable;
98+ dst=table->colors;
99+ for (i=0; i<n; i++) {
100+ dst->red=src->rgb.red;
101+ dst->green=src->rgb.green;
102+ dst->blue=src->rgb.blue;
103+ src++;
104+ dst++;
105+ }
106+}
--- marathon/trunk/Source_Files/CSeries/csmisc.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/csmisc.cpp (revision 522)
@@ -1,66 +1,66 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-Jan 25, 2002 (Br'fin (Jeremy Parsons)):
21- Added TARGET_API_MAC_CARBON for Carbon.h
22- Carbon uses GetNextEvent instead of GetOSEvent
23-*/
24-
25-#if defined(EXPLICIT_CARBON_HEADER)
26- #include <Carbon/Carbon.h>
27-/*
28-#else
29-#include <Events.h>
30-*/
31-#endif
32-
33-#include "cstypes.h"
34-#include "csmisc.h"
35-
36-extern void initialize_debugger(bool);
37-
38-uint32 machine_tick_count(void)
39-{
40- return TickCount();
41-}
42-
43-bool wait_for_click_or_keypress(
44- unsigned long ticks)
45-{
46- unsigned long end;
47- EventRecord event;
48-
49- end=TickCount()+ticks;
50- for (;;) {
51- if (GetNextEvent(mDownMask|keyDownMask,&event))
52- return true;
53- if (event.when>=end)
54- return false;
55- }
56-}
57-
58-void kill_screen_saver(void)
59-{
60-}
61-
62-void initialize_debugger(
63- bool ignore)
64-{
65- (void)ignore;
66-}
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+Jan 25, 2002 (Br'fin (Jeremy Parsons)):
21+ Added TARGET_API_MAC_CARBON for Carbon.h
22+ Carbon uses GetNextEvent instead of GetOSEvent
23+*/
24+
25+#if defined(EXPLICIT_CARBON_HEADER)
26+ #include <Carbon/Carbon.h>
27+/*
28+#else
29+#include <Events.h>
30+*/
31+#endif
32+
33+#include "cstypes.h"
34+#include "csmisc.h"
35+
36+extern void initialize_debugger(bool);
37+
38+uint32 machine_tick_count(void)
39+{
40+ return TickCount();
41+}
42+
43+bool wait_for_click_or_keypress(
44+ unsigned long ticks)
45+{
46+ unsigned long end;
47+ EventRecord event;
48+
49+ end=TickCount()+ticks;
50+ for (;;) {
51+ if (GetNextEvent(mDownMask|keyDownMask,&event))
52+ return true;
53+ if (event.when>=end)
54+ return false;
55+ }
56+}
57+
58+void kill_screen_saver(void)
59+{
60+}
61+
62+void initialize_debugger(
63+ bool ignore)
64+{
65+ (void)ignore;
66+}
--- marathon/trunk/Source_Files/CSeries/cscluts_sdl.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/cscluts_sdl.cpp (revision 522)
@@ -1,74 +1,74 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-/*
22- * cscluts_sdl.cpp - CLUT handling, SDL implementation
23- *
24- * Written in 2000 by Christian Bauer
25- */
26-
27-#include "cseries.h"
28-#include "FileHandler.h"
29-#include "SDL_endian.h"
30-
31-
32-// Global variables
33-RGBColor rgb_black = {0x0000, 0x0000, 0x0000};
34-RGBColor rgb_white = {0xffff, 0xffff, 0xffff};
35-
36-RGBColor system_colors[NUM_SYSTEM_COLORS] =
37-{
38- {0x2666, 0x2666, 0x2666},
39- {0xd999, 0xd999, 0xd999}
40-};
41-
42-
43-/*
44- * Convert Mac CLUT resource to color_table
45- */
46-
47-void build_color_table(color_table *table, LoadedResource &clut)
48-{
49- // Open stream to CLUT resource
50- SDL_RWops *p = SDL_RWFromMem(clut.GetPointer(), (int)clut.GetLength());
51- assert(p);
52-
53- // Check number of colors
54- SDL_RWseek(p, 6, SEEK_CUR);
55- int n = SDL_ReadBE16(p) + 1;
56- if (n < 0)
57- n = 0;
58- else if (n > 256)
59- n = 256;
60- table->color_count = n;
61-
62- // Convert color data
63- rgb_color *dst = table->colors;
64- for (int i=0; i<n; i++) {
65- SDL_RWseek(p, 2, SEEK_CUR);
66- dst->red = SDL_ReadBE16(p);
67- dst->green = SDL_ReadBE16(p);
68- dst->blue = SDL_ReadBE16(p);
69- dst++;
70- }
71-
72- // Close stream
73- SDL_RWclose(p);
74-}
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+/*
22+ * cscluts_sdl.cpp - CLUT handling, SDL implementation
23+ *
24+ * Written in 2000 by Christian Bauer
25+ */
26+
27+#include "cseries.h"
28+#include "FileHandler.h"
29+#include "SDL_endian.h"
30+
31+
32+// Global variables
33+RGBColor rgb_black = {0x0000, 0x0000, 0x0000};
34+RGBColor rgb_white = {0xffff, 0xffff, 0xffff};
35+
36+RGBColor system_colors[NUM_SYSTEM_COLORS] =
37+{
38+ {0x2666, 0x2666, 0x2666},
39+ {0xd999, 0xd999, 0xd999}
40+};
41+
42+
43+/*
44+ * Convert Mac CLUT resource to color_table
45+ */
46+
47+void build_color_table(color_table *table, LoadedResource &clut)
48+{
49+ // Open stream to CLUT resource
50+ SDL_RWops *p = SDL_RWFromMem(clut.GetPointer(), (int)clut.GetLength());
51+ assert(p);
52+
53+ // Check number of colors
54+ SDL_RWseek(p, 6, SEEK_CUR);
55+ int n = SDL_ReadBE16(p) + 1;
56+ if (n < 0)
57+ n = 0;
58+ else if (n > 256)
59+ n = 256;
60+ table->color_count = n;
61+
62+ // Convert color data
63+ rgb_color *dst = table->colors;
64+ for (int i=0; i<n; i++) {
65+ SDL_RWseek(p, 2, SEEK_CUR);
66+ dst->red = SDL_ReadBE16(p);
67+ dst->green = SDL_ReadBE16(p);
68+ dst->blue = SDL_ReadBE16(p);
69+ dst++;
70+ }
71+
72+ // Close stream
73+ SDL_RWclose(p);
74+}
--- marathon/trunk/Source_Files/CSeries/csmisc_sdl.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/csmisc_sdl.cpp (revision 522)
@@ -1,55 +1,55 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-/*
22- * csmisc_sdl.cpp - Miscellaneous routines, SDL implementation
23- *
24- * Written in 2000 by Christian Bauer
25- */
26-
27-#include "cseries.h"
28-
29-
30-/*
31- * Return tick counter
32- */
33-
34-uint32 machine_tick_count(void)
35-{
36- return SDL_GetTicks();
37-}
38-
39-
40-/*
41- * Wait for mouse click or keypress
42- */
43-
44-bool wait_for_click_or_keypress(uint32 ticks)
45-{
46- uint32 start = SDL_GetTicks();
47- SDL_Event event;
48- while (SDL_GetTicks() - start < ticks) {
49- SDL_PollEvent(&event);
50- if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_KEYDOWN)
51- return true;
52- SDL_Delay(10);
53- }
54- return false;
55-}
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+/*
22+ * csmisc_sdl.cpp - Miscellaneous routines, SDL implementation
23+ *
24+ * Written in 2000 by Christian Bauer
25+ */
26+
27+#include "cseries.h"
28+
29+
30+/*
31+ * Return tick counter
32+ */
33+
34+uint32 machine_tick_count(void)
35+{
36+ return SDL_GetTicks();
37+}
38+
39+
40+/*
41+ * Wait for mouse click or keypress
42+ */
43+
44+bool wait_for_click_or_keypress(uint32 ticks)
45+{
46+ uint32 start = SDL_GetTicks();
47+ SDL_Event event;
48+ while (SDL_GetTicks() - start < ticks) {
49+ SDL_PollEvent(&event);
50+ if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_KEYDOWN)
51+ return true;
52+ SDL_Delay(10);
53+ }
54+ return false;
55+}
--- marathon/trunk/Source_Files/CSeries/csfonts.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/csfonts.h (revision 522)
@@ -1,52 +1,52 @@
1-/* csfonts.h
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-
21- Sept-Nov 2001 (Woody Zenfell): new styleOutline helps put a "halo" (heh) around text.
22-*/
23-
24-#ifndef _CSERIES_FONTS_
25-#define _CSERIES_FONTS_
26-
27-#include "cstypes.h"
28-#include <string>
29-
30-const int styleNormal = 0;
31-const int styleBold = 1;
32-const int styleItalic = 2;
33-const int styleUnderline = 4;
34-// const int styleOutline = 8; -- can't be used with TTF
35-const int styleShadow = 16;
36-
37-struct TextSpec {
38- int16 font;
39-
40- uint16 style;
41- int16 size;
42- int16 adjust_height;
43-
44- // paths to fonts
45- std::string normal;
46- std::string oblique;
47- std::string bold;
48- std::string bold_oblique;
49-};
50-
51-#endif
52-
1+/* csfonts.h
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+
21+ Sept-Nov 2001 (Woody Zenfell): new styleOutline helps put a "halo" (heh) around text.
22+*/
23+
24+#ifndef _CSERIES_FONTS_
25+#define _CSERIES_FONTS_
26+
27+#include "cstypes.h"
28+#include <string>
29+
30+const int styleNormal = 0;
31+const int styleBold = 1;
32+const int styleItalic = 2;
33+const int styleUnderline = 4;
34+// const int styleOutline = 8; -- can't be used with TTF
35+const int styleShadow = 16;
36+
37+struct TextSpec {
38+ int16 font;
39+
40+ uint16 style;
41+ int16 size;
42+ int16 adjust_height;
43+
44+ // paths to fonts
45+ std::string normal;
46+ std::string oblique;
47+ std::string bold;
48+ std::string bold_oblique;
49+};
50+
51+#endif
52+
--- marathon/trunk/Source_Files/CSeries/my32bqd.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/my32bqd.h (revision 522)
@@ -1,78 +1,78 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-Jan 25, 2002 (Br'fin (Jeremy Parsons)):
21- Added TARGET_API_MAC_CARBON for Carbon.h
22-*/
23-
24-#ifndef _MY_32BIT_QUICKDRAW_
25-#define _MY_32BIT_QUICKDRAW_
26-
27-#if defined(EXPLICIT_CARBON_HEADER)
28- #include <Carbon/Carbon.h>
29-/*
30-#else
31-#include <QDOffscreen.h>
32-*/
33-#endif
34-
35-
36-extern void initialize_my_32bqd(void);
37-
38-extern void myGetGWorld(
39- GWorldPtr *gw,
40- GDHandle *dev);
41-extern void mySetGWorld(
42- GWorldPtr gw,
43- GDHandle dev);
44-extern OSErr myNewGWorld(
45- GWorldPtr *gw,
46- short depth,
47- Rect *bounds,
48- CTabHandle clut,
49- GDHandle dev,
50- unsigned long flags);
51-extern OSErr myUpdateGWorld(
52- GWorldPtr *gw,
53- short depth,
54- Rect *bounds,
55- CTabHandle clut,
56- GDHandle dev,
57- unsigned long flags);
58-extern void myDisposeGWorld(
59- GWorldPtr gw);
60-extern bool myLockPixels(
61- GWorldPtr gw);
62-extern void myUnlockPixels(
63- GWorldPtr gw);
64-extern PixMapHandle myGetGWorldPixMap(
65- GWorldPtr gw);
66-extern Ptr myGetPixBaseAddr(
67- GWorldPtr gw);
68-
69-extern void myHideMenuBar(
70- GDHandle dev);
71-extern void myShowMenuBar(void);
72-
73-extern void LowLevelSetEntries(
74- short start,
75- short count0,
76- ColorSpec *specs);
77-
78-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+Jan 25, 2002 (Br'fin (Jeremy Parsons)):
21+ Added TARGET_API_MAC_CARBON for Carbon.h
22+*/
23+
24+#ifndef _MY_32BIT_QUICKDRAW_
25+#define _MY_32BIT_QUICKDRAW_
26+
27+#if defined(EXPLICIT_CARBON_HEADER)
28+ #include <Carbon/Carbon.h>
29+/*
30+#else
31+#include <QDOffscreen.h>
32+*/
33+#endif
34+
35+
36+extern void initialize_my_32bqd(void);
37+
38+extern void myGetGWorld(
39+ GWorldPtr *gw,
40+ GDHandle *dev);
41+extern void mySetGWorld(
42+ GWorldPtr gw,
43+ GDHandle dev);
44+extern OSErr myNewGWorld(
45+ GWorldPtr *gw,
46+ short depth,
47+ Rect *bounds,
48+ CTabHandle clut,
49+ GDHandle dev,
50+ unsigned long flags);
51+extern OSErr myUpdateGWorld(
52+ GWorldPtr *gw,
53+ short depth,
54+ Rect *bounds,
55+ CTabHandle clut,
56+ GDHandle dev,
57+ unsigned long flags);
58+extern void myDisposeGWorld(
59+ GWorldPtr gw);
60+extern bool myLockPixels(
61+ GWorldPtr gw);
62+extern void myUnlockPixels(
63+ GWorldPtr gw);
64+extern PixMapHandle myGetGWorldPixMap(
65+ GWorldPtr gw);
66+extern Ptr myGetPixBaseAddr(
67+ GWorldPtr gw);
68+
69+extern void myHideMenuBar(
70+ GDHandle dev);
71+extern void myShowMenuBar(void);
72+
73+extern void LowLevelSetEntries(
74+ short start,
75+ short count0,
76+ ColorSpec *specs);
77+
78+#endif
--- marathon/trunk/Source_Files/CSeries/mytm_sdl.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/mytm_sdl.cpp (revision 522)
@@ -1,370 +1,370 @@
1-/*
2- * mytm_sdl.cpp
3-
4- Copyright (C) 2001 and beyond by Woody Zenfell, III
5- and the "Aleph One" developers.
6-
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 3 of the License, or
10- (at your option) any later version.
11-
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.
16-
17- This license is contained in the file "COPYING",
18- which is included with this source code; it is available online at
19- http://www.gnu.org/licenses/gpl.html
20-
21- * The point of this file is to let us (networking code, in particular) use timing services
22- * with the same source-level API wrapper that Bungie used to access the Mac's Time Manager.
23- *
24- * Created by woody on Mon Oct 15 2001.
25- *
26- * 3 December 2001 (Woody Zenfell): changed dependence on SDL_Threadx's SetRelativeThreadPriority
27- * to simply BoostThreadPriority(), a simpler function with a simpler interface.
28- *
29- * 14 January 2003 (Woody Zenfell): TMTasks lock each other out while running (better models
30- * Time Manager behavior, so makes code safer). Also removed missedDeadline stuff.
31- */
32-
33-// The implementation is built on SDL_thread, and approximates the Time Manager behavior.
34-// Obviously, it's not a perfect emulation. :)
35-// In particular, though TMTasks now lock one another out (as they should), TMTasks do not
36-// (cannot?) effectively lock out the main thread (as they would in Mac OS 9)... but, their
37-// threads ought to be higher-priority than the main thread, which means that as long as they
38-// don't block (which they shouldn't anyway), the main thread will not run while they do.
39-
40-// I probably would have made life easier for myself by using SDL_timer instead, but frankly
41-// the documentation does not inspire me to trust it. I'll do things on my own.
42-
43-#include "cseries.h"
44-#include "thread_priority_sdl.h"
45-#include "mytm.h"
46-
47-#include <vector>
48-
49-#include "SDL_thread.h"
50-#include "SDL_timer.h"
51-#include "SDL_error.h"
52-
53-#include "Logging.h"
54-
55-#ifndef NO_STD_NAMESPACE
56-using std::vector;
57-#endif
58-
59-#ifdef DEBUG
60-struct myTMTask_profile {
61- uint32 mStartTime;
62- uint32 mFinishTime;
63- uint32 mNumCallsThisReset;
64- uint32 mNumCallsTotal;
65- int32 mDriftMin;
66- int32 mDriftMax;
67- uint32 mNumLateCalls;
68- uint32 mNumWarmResets;
69- uint32 mNumResuscitations;
70-};
71-#endif
72-
73-// Housekeeping structure used in setup, teardown, and execution
74-struct myTMTask {
75- SDL_Thread* mThread;
76- uint32 mPeriod;
77- bool (*mFunction)(void);
78- volatile bool mKeepRunning; // set true by myTMSetup; set false by thread or by myTMRemove.
79- volatile bool mIsRunning; // set true by myTMSetup; set false by thread when about to exit.
80- volatile uint32 mResetTime; // set positive by myTMReset; set to 0 by myTMSetup or by thread.
81-#ifdef DEBUG
82- myTMTask_profile mProfilingData;
83-#endif
84-};
85-
86-// Only one TMTask should be scheduled at any given time, so they take this mutex.
87-static SDL_mutex* sTMTaskMutex = NULL;
88-
89-
90-void
91-mytm_initialize() {
92- // XXX should provide a way to destroy the mutex too - currently we rely on process exit to do that.
93- if(sTMTaskMutex == NULL) {
94- sTMTaskMutex = SDL_CreateMutex();
95-
96- //logCheckWarn0(sTMTaskMutex != NULL, "unable to create mytm mutex lock");
97- if(sTMTaskMutex == NULL)
98- logWarning("unable to create mytm mutex lock");
99- }
100- else
101- logAnomaly("multiple invocations of mytm_initialize()");
102-}
103-
104-
105-// The logging system is not (currently) thread-safe, so these logging calls are potentially a Bad Idea
106-// but if something's going wrong already, maybe it wouldn't hurt to take a small risk to shed some light.
107-bool
108-take_mytm_mutex() {
109- bool success = (SDL_LockMutex(sTMTaskMutex) != -1);
110- if(!success)
111- logAnomaly1("take_mytm_mutex(): SDL_LockMutex() failed: %s", SDL_GetError());
112- return success;
113-}
114-
115-
116-
117-bool
118-release_mytm_mutex() {
119- bool success = (SDL_UnlockMutex(sTMTaskMutex) != -1);
120- if(!success)
121- logAnomaly1("release_mytm_mutex(): SDL_UnlockMutex() failed: %s", SDL_GetError());
122- return success;
123-}
124-
125-
126-
127-// Function that threads execute - does housekeeping and calls user callback
128-// Tries to be drift-free.
129-static int
130-thread_loop(void* inData) {
131- myTMTask* theTMTask = (myTMTask*) inData;
132-
133- uint32 theLastRunTime = SDL_GetTicks();
134- uint32 theCurrentRunTime;
135- int32 theDrift = 0;
136-
137-#ifdef DEBUG
138- theTMTask->mProfilingData.mStartTime = theLastRunTime;
139-#endif
140-
141- while(theTMTask->mKeepRunning) {
142- // Delay, unless we're at least a period behind schedule
143- // Originally, I didn't compute theDelay explicitly as a signed quantity, which
144- // made for some VERY long waits if we were running late...
145- int32 theDelay = theTMTask->mPeriod - theDrift;
146- if(theDelay > 0)
147- SDL_Delay(theDelay);
148- else {
149- // We missed a deadline!
150-#ifdef DEBUG
151- theTMTask->mProfilingData.mNumLateCalls++;
152-#endif
153- }
154-
155- // If a reset was requested, pretend we were last called at the reset time, clear the reset,
156- // and delay some more if needed.
157- // Note: this is a "while" so, in case another reset comes while we are in the Delay() inside
158- // this block, we wait longer.
159- while(theTMTask->mResetTime > 0) {
160- theLastRunTime = theTMTask->mResetTime;
161- theTMTask->mResetTime = 0;
162-
163-#ifdef DEBUG
164- theTMTask->mProfilingData.mNumWarmResets++;
165- theTMTask->mProfilingData.mStartTime = theLastRunTime;
166- theTMTask->mProfilingData.mNumCallsThisReset = 0;
167-#endif
168-
169- theCurrentRunTime = SDL_GetTicks();
170- theDrift += theCurrentRunTime - theLastRunTime - theTMTask->mPeriod;
171- theLastRunTime = theCurrentRunTime;
172-
173-#ifdef DEBUG
174- if(theDrift < theTMTask->mProfilingData.mDriftMin)
175- theTMTask->mProfilingData.mDriftMin = theDrift;
176-
177- if(theDrift > theTMTask->mProfilingData.mDriftMax)
178- theTMTask->mProfilingData.mDriftMax = theDrift;
179-#endif
180-
181- theDelay = theTMTask->mPeriod - theDrift;
182-
183- if(theDelay > 0)
184- SDL_Delay(theDelay);
185- else {
186- // We did miss a deadline!
187-#ifdef DEBUG
188- theTMTask->mProfilingData.mNumLateCalls++;
189-#endif
190- }
191- }
192-
193- theCurrentRunTime = SDL_GetTicks();
194- theDrift += theCurrentRunTime - theLastRunTime - theTMTask->mPeriod;
195- theLastRunTime = theCurrentRunTime;
196-
197-#ifdef DEBUG
198- if(theDrift < theTMTask->mProfilingData.mDriftMin)
199- theTMTask->mProfilingData.mDriftMin = theDrift;
200-
201- if(theDrift > theTMTask->mProfilingData.mDriftMax)
202- theTMTask->mProfilingData.mDriftMax = theDrift;
203-#endif
204-
205- // Since we've been delayed for a while, double-check that we still want to run.
206- if(theTMTask->mKeepRunning == false)
207- break;
208-
209- // NOTE: since we could be preempted between checking for termination and actually calling the
210- // callback, there is a VERY small chance that mFunction could be called (at most once) after
211- // myTMRemoveTask() completes. This is a BUG, but to avoid expensive synchronization (making
212- // myTMRemoveTask() block until this thread finishes, protecting mKeepRunning with a mutex, etc.)
213- // we take our chances. This bug could only bite anyway (in the current IPring) while making the
214- // transition from a normal player to the gatherer (in drop_upring_player()) as a result of the
215- // gatherer becoming netdead - not terribly likely to begin with!
216-
217- // Call the function. If it doesn't want to be rescheduled, stop ourselves.
218-#ifdef DEBUG
219- theTMTask->mProfilingData.mNumCallsThisReset++;
220- theTMTask->mProfilingData.mNumCallsTotal++;
221-#endif
222-
223- bool runAgain = true;
224-
225- // Lock out other tmtasks while we run ours
226- if(take_mytm_mutex()) {
227- runAgain = theTMTask->mFunction();
228- release_mytm_mutex();
229- }
230-
231- if(!runAgain)
232- break;
233- }
234-
235- theTMTask->mIsRunning = false;
236-
237-#ifdef DEBUG
238- theTMTask->mProfilingData.mFinishTime = SDL_GetTicks();
239-#endif
240-
241- return 0;
242-}
243-
244-
245-static vector<myTMTaskPtr> sOutstandingTasks;
246-
247-
248-// Set up a periodic callout with no anti-drift mechanisms. (We don't support that,
249-// but it's unlikely that anyone is counting on NOT having drift-correction?)
250-myTMTaskPtr
251-myTMSetup(int32 time, bool (*func)(void)) {
252- return myXTMSetup(time, func);
253-}
254-
255-// Set up a periodic callout, with what tries to be a fairly drift-free period.
256-myTMTaskPtr
257-myXTMSetup(int32 time, bool (*func)(void)) {
258- myTMTaskPtr theTask = new myTMTask;
259-
260- theTask->mPeriod = time;
261- theTask->mFunction = func;
262- theTask->mKeepRunning = true;
263- theTask->mIsRunning = true;
264- theTask->mResetTime = 0;
265-
266-#ifdef DEBUG
267- obj_clear(theTask->mProfilingData);
268-#endif
269-
270- theTask->mThread = SDL_CreateThread(thread_loop, theTask);
271-
272- // Set thread priority a little higher
273- BoostThreadPriority(theTask->mThread);
274-
275- sOutstandingTasks.push_back(theTask);
276-
277- return theTask;
278-}
279-
280-// Stop an existing callout from executing.
281-myTMTaskPtr
282-myTMRemove(myTMTaskPtr task) {
283- if(task != NULL)
284- task->mKeepRunning = false;
285-
286- return NULL;
287-}
288-
289-// Reset an existing callout's delay to the original value.
290-// This is similar to myTMRemove() followed by another myTMSetup() with the same task and period.
291-void
292-myTMReset(myTMTaskPtr task) {
293- if(task != NULL) {
294- // If the thread has not exited, we can message it. NOTE: there is a small possibility
295- // that the thread has already broken its loop, but got preempted before it could set
296- // mIsRunning to false. I'm going to take the easy lazy evil way out and just hope that
297- // doesn't happen.
298- if(task->mIsRunning)
299- task->mResetTime = SDL_GetTicks();
300-
301- // Otherwise, we need to start a new thread for the task.
302- else {
303- // This is our only chance to clean up that zombie thread. This should not block.
304- SDL_WaitThread(task->mThread, NULL);
305-
306- task->mKeepRunning = true;
307- task->mIsRunning = true;
308- task->mResetTime = 0;
309-
310-#ifdef DEBUG
311- task->mProfilingData.mNumResuscitations++;
312- task->mProfilingData.mNumCallsThisReset = 0;
313-#endif
314-
315- task->mThread = SDL_CreateThread(thread_loop, task);
316-
317- // Set thread priority a little higher
318- BoostThreadPriority(task->mThread);
319- }
320- }
321-}
322-
323-#ifdef DEBUG
324-// ZZZ addition (to myTM interface): dump profiling data
325-#define DUMPIT_ZU(structure,field_name) logDump1("" #field_name ":\t%u", (structure).field_name)
326-#define DUMPIT_ZS(structure,field_name) logDump1("" #field_name ":\t%d", (structure).field_name)
327-
328-void
329-myTMDumpProfile(myTMTask* inTask) {
330- if(inTask != NULL) {
331- logDump2("PROFILE FOR SDL TMTASK %p (function %p)", inTask, inTask->mFunction);
332- DUMPIT_ZU((*inTask), mPeriod);
333- DUMPIT_ZU(inTask->mProfilingData, mStartTime);
334- DUMPIT_ZU(inTask->mProfilingData, mFinishTime);
335- DUMPIT_ZU(inTask->mProfilingData, mNumCallsThisReset);
336- DUMPIT_ZU(inTask->mProfilingData, mNumCallsTotal);
337- DUMPIT_ZS(inTask->mProfilingData, mDriftMin);
338- DUMPIT_ZS(inTask->mProfilingData, mDriftMax);
339- DUMPIT_ZU(inTask->mProfilingData, mNumLateCalls);
340- DUMPIT_ZU(inTask->mProfilingData, mNumWarmResets);
341- DUMPIT_ZU(inTask->mProfilingData, mNumResuscitations);
342- }
343-}
344-#endif//DEBUG
345-
346-// ZZZ addition: clean up outstanding timer task blocks and threads
347-// This could be slightly more efficient maybe by using a list, condensing calls to erase(), etc...
348-// but why bother? It's only used occasionally at non-time-critical moments, and we're only dealing with
349-// a small handful of (small) elements anyway.
350-void
351-myTMCleanup(bool inWaitForFinishers) {
352- vector<myTMTaskPtr>::iterator i;
353-
354- for(i = sOutstandingTasks.begin(); i != sOutstandingTasks.end(); ++i) {
355- if((*i)->mKeepRunning == false && (inWaitForFinishers || (*i)->mIsRunning == false)) {
356- myTMTaskPtr theDeadTask = *i;
357-
358- // This does the right thing: i is sent to erase(), but before erase is called, i is decremented so
359- // the iterator remains valid.
360- sOutstandingTasks.erase(i--);
361-
362-#ifdef DEBUG
363- myTMDumpProfile(theDeadTask);
364-#endif
365-
366- SDL_WaitThread(theDeadTask->mThread, NULL);
367- delete theDeadTask;
368- }
369- }
370-}
1+/*
2+ * mytm_sdl.cpp
3+
4+ Copyright (C) 2001 and beyond by Woody Zenfell, III
5+ and the "Aleph One" developers.
6+
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 3 of the License, or
10+ (at your option) any later version.
11+
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.
16+
17+ This license is contained in the file "COPYING",
18+ which is included with this source code; it is available online at
19+ http://www.gnu.org/licenses/gpl.html
20+
21+ * The point of this file is to let us (networking code, in particular) use timing services
22+ * with the same source-level API wrapper that Bungie used to access the Mac's Time Manager.
23+ *
24+ * Created by woody on Mon Oct 15 2001.
25+ *
26+ * 3 December 2001 (Woody Zenfell): changed dependence on SDL_Threadx's SetRelativeThreadPriority
27+ * to simply BoostThreadPriority(), a simpler function with a simpler interface.
28+ *
29+ * 14 January 2003 (Woody Zenfell): TMTasks lock each other out while running (better models
30+ * Time Manager behavior, so makes code safer). Also removed missedDeadline stuff.
31+ */
32+
33+// The implementation is built on SDL_thread, and approximates the Time Manager behavior.
34+// Obviously, it's not a perfect emulation. :)
35+// In particular, though TMTasks now lock one another out (as they should), TMTasks do not
36+// (cannot?) effectively lock out the main thread (as they would in Mac OS 9)... but, their
37+// threads ought to be higher-priority than the main thread, which means that as long as they
38+// don't block (which they shouldn't anyway), the main thread will not run while they do.
39+
40+// I probably would have made life easier for myself by using SDL_timer instead, but frankly
41+// the documentation does not inspire me to trust it. I'll do things on my own.
42+
43+#include "cseries.h"
44+#include "thread_priority_sdl.h"
45+#include "mytm.h"
46+
47+#include <vector>
48+
49+#include "SDL_thread.h"
50+#include "SDL_timer.h"
51+#include "SDL_error.h"
52+
53+#include "Logging.h"
54+
55+#ifndef NO_STD_NAMESPACE
56+using std::vector;
57+#endif
58+
59+#ifdef DEBUG
60+struct myTMTask_profile {
61+ uint32 mStartTime;
62+ uint32 mFinishTime;
63+ uint32 mNumCallsThisReset;
64+ uint32 mNumCallsTotal;
65+ int32 mDriftMin;
66+ int32 mDriftMax;
67+ uint32 mNumLateCalls;
68+ uint32 mNumWarmResets;
69+ uint32 mNumResuscitations;
70+};
71+#endif
72+
73+// Housekeeping structure used in setup, teardown, and execution
74+struct myTMTask {
75+ SDL_Thread* mThread;
76+ uint32 mPeriod;
77+ bool (*mFunction)(void);
78+ volatile bool mKeepRunning; // set true by myTMSetup; set false by thread or by myTMRemove.
79+ volatile bool mIsRunning; // set true by myTMSetup; set false by thread when about to exit.
80+ volatile uint32 mResetTime; // set positive by myTMReset; set to 0 by myTMSetup or by thread.
81+#ifdef DEBUG
82+ myTMTask_profile mProfilingData;
83+#endif
84+};
85+
86+// Only one TMTask should be scheduled at any given time, so they take this mutex.
87+static SDL_mutex* sTMTaskMutex = NULL;
88+
89+
90+void
91+mytm_initialize() {
92+ // XXX should provide a way to destroy the mutex too - currently we rely on process exit to do that.
93+ if(sTMTaskMutex == NULL) {
94+ sTMTaskMutex = SDL_CreateMutex();
95+
96+ //logCheckWarn0(sTMTaskMutex != NULL, "unable to create mytm mutex lock");
97+ if(sTMTaskMutex == NULL)
98+ logWarning("unable to create mytm mutex lock");
99+ }
100+ else
101+ logAnomaly("multiple invocations of mytm_initialize()");
102+}
103+
104+
105+// The logging system is not (currently) thread-safe, so these logging calls are potentially a Bad Idea
106+// but if something's going wrong already, maybe it wouldn't hurt to take a small risk to shed some light.
107+bool
108+take_mytm_mutex() {
109+ bool success = (SDL_LockMutex(sTMTaskMutex) != -1);
110+ if(!success)
111+ logAnomaly1("take_mytm_mutex(): SDL_LockMutex() failed: %s", SDL_GetError());
112+ return success;
113+}
114+
115+
116+
117+bool
118+release_mytm_mutex() {
119+ bool success = (SDL_UnlockMutex(sTMTaskMutex) != -1);
120+ if(!success)
121+ logAnomaly1("release_mytm_mutex(): SDL_UnlockMutex() failed: %s", SDL_GetError());
122+ return success;
123+}
124+
125+
126+
127+// Function that threads execute - does housekeeping and calls user callback
128+// Tries to be drift-free.
129+static int
130+thread_loop(void* inData) {
131+ myTMTask* theTMTask = (myTMTask*) inData;
132+
133+ uint32 theLastRunTime = SDL_GetTicks();
134+ uint32 theCurrentRunTime;
135+ int32 theDrift = 0;
136+
137+#ifdef DEBUG
138+ theTMTask->mProfilingData.mStartTime = theLastRunTime;
139+#endif
140+
141+ while(theTMTask->mKeepRunning) {
142+ // Delay, unless we're at least a period behind schedule
143+ // Originally, I didn't compute theDelay explicitly as a signed quantity, which
144+ // made for some VERY long waits if we were running late...
145+ int32 theDelay = theTMTask->mPeriod - theDrift;
146+ if(theDelay > 0)
147+ SDL_Delay(theDelay);
148+ else {
149+ // We missed a deadline!
150+#ifdef DEBUG
151+ theTMTask->mProfilingData.mNumLateCalls++;
152+#endif
153+ }
154+
155+ // If a reset was requested, pretend we were last called at the reset time, clear the reset,
156+ // and delay some more if needed.
157+ // Note: this is a "while" so, in case another reset comes while we are in the Delay() inside
158+ // this block, we wait longer.
159+ while(theTMTask->mResetTime > 0) {
160+ theLastRunTime = theTMTask->mResetTime;
161+ theTMTask->mResetTime = 0;
162+
163+#ifdef DEBUG
164+ theTMTask->mProfilingData.mNumWarmResets++;
165+ theTMTask->mProfilingData.mStartTime = theLastRunTime;
166+ theTMTask->mProfilingData.mNumCallsThisReset = 0;
167+#endif
168+
169+ theCurrentRunTime = SDL_GetTicks();
170+ theDrift += theCurrentRunTime - theLastRunTime - theTMTask->mPeriod;
171+ theLastRunTime = theCurrentRunTime;
172+
173+#ifdef DEBUG
174+ if(theDrift < theTMTask->mProfilingData.mDriftMin)
175+ theTMTask->mProfilingData.mDriftMin = theDrift;
176+
177+ if(theDrift > theTMTask->mProfilingData.mDriftMax)
178+ theTMTask->mProfilingData.mDriftMax = theDrift;
179+#endif
180+
181+ theDelay = theTMTask->mPeriod - theDrift;
182+
183+ if(theDelay > 0)
184+ SDL_Delay(theDelay);
185+ else {
186+ // We did miss a deadline!
187+#ifdef DEBUG
188+ theTMTask->mProfilingData.mNumLateCalls++;
189+#endif
190+ }
191+ }
192+
193+ theCurrentRunTime = SDL_GetTicks();
194+ theDrift += theCurrentRunTime - theLastRunTime - theTMTask->mPeriod;
195+ theLastRunTime = theCurrentRunTime;
196+
197+#ifdef DEBUG
198+ if(theDrift < theTMTask->mProfilingData.mDriftMin)
199+ theTMTask->mProfilingData.mDriftMin = theDrift;
200+
201+ if(theDrift > theTMTask->mProfilingData.mDriftMax)
202+ theTMTask->mProfilingData.mDriftMax = theDrift;
203+#endif
204+
205+ // Since we've been delayed for a while, double-check that we still want to run.
206+ if(theTMTask->mKeepRunning == false)
207+ break;
208+
209+ // NOTE: since we could be preempted between checking for termination and actually calling the
210+ // callback, there is a VERY small chance that mFunction could be called (at most once) after
211+ // myTMRemoveTask() completes. This is a BUG, but to avoid expensive synchronization (making
212+ // myTMRemoveTask() block until this thread finishes, protecting mKeepRunning with a mutex, etc.)
213+ // we take our chances. This bug could only bite anyway (in the current IPring) while making the
214+ // transition from a normal player to the gatherer (in drop_upring_player()) as a result of the
215+ // gatherer becoming netdead - not terribly likely to begin with!
216+
217+ // Call the function. If it doesn't want to be rescheduled, stop ourselves.
218+#ifdef DEBUG
219+ theTMTask->mProfilingData.mNumCallsThisReset++;
220+ theTMTask->mProfilingData.mNumCallsTotal++;
221+#endif
222+
223+ bool runAgain = true;
224+
225+ // Lock out other tmtasks while we run ours
226+ if(take_mytm_mutex()) {
227+ runAgain = theTMTask->mFunction();
228+ release_mytm_mutex();
229+ }
230+
231+ if(!runAgain)
232+ break;
233+ }
234+
235+ theTMTask->mIsRunning = false;
236+
237+#ifdef DEBUG
238+ theTMTask->mProfilingData.mFinishTime = SDL_GetTicks();
239+#endif
240+
241+ return 0;
242+}
243+
244+
245+static vector<myTMTaskPtr> sOutstandingTasks;
246+
247+
248+// Set up a periodic callout with no anti-drift mechanisms. (We don't support that,
249+// but it's unlikely that anyone is counting on NOT having drift-correction?)
250+myTMTaskPtr
251+myTMSetup(int32 time, bool (*func)(void)) {
252+ return myXTMSetup(time, func);
253+}
254+
255+// Set up a periodic callout, with what tries to be a fairly drift-free period.
256+myTMTaskPtr
257+myXTMSetup(int32 time, bool (*func)(void)) {
258+ myTMTaskPtr theTask = new myTMTask;
259+
260+ theTask->mPeriod = time;
261+ theTask->mFunction = func;
262+ theTask->mKeepRunning = true;
263+ theTask->mIsRunning = true;
264+ theTask->mResetTime = 0;
265+
266+#ifdef DEBUG
267+ obj_clear(theTask->mProfilingData);
268+#endif
269+
270+ theTask->mThread = SDL_CreateThread(thread_loop, theTask);
271+
272+ // Set thread priority a little higher
273+ BoostThreadPriority(theTask->mThread);
274+
275+ sOutstandingTasks.push_back(theTask);
276+
277+ return theTask;
278+}
279+
280+// Stop an existing callout from executing.
281+myTMTaskPtr
282+myTMRemove(myTMTaskPtr task) {
283+ if(task != NULL)
284+ task->mKeepRunning = false;
285+
286+ return NULL;
287+}
288+
289+// Reset an existing callout's delay to the original value.
290+// This is similar to myTMRemove() followed by another myTMSetup() with the same task and period.
291+void
292+myTMReset(myTMTaskPtr task) {
293+ if(task != NULL) {
294+ // If the thread has not exited, we can message it. NOTE: there is a small possibility
295+ // that the thread has already broken its loop, but got preempted before it could set
296+ // mIsRunning to false. I'm going to take the easy lazy evil way out and just hope that
297+ // doesn't happen.
298+ if(task->mIsRunning)
299+ task->mResetTime = SDL_GetTicks();
300+
301+ // Otherwise, we need to start a new thread for the task.
302+ else {
303+ // This is our only chance to clean up that zombie thread. This should not block.
304+ SDL_WaitThread(task->mThread, NULL);
305+
306+ task->mKeepRunning = true;
307+ task->mIsRunning = true;
308+ task->mResetTime = 0;
309+
310+#ifdef DEBUG
311+ task->mProfilingData.mNumResuscitations++;
312+ task->mProfilingData.mNumCallsThisReset = 0;
313+#endif
314+
315+ task->mThread = SDL_CreateThread(thread_loop, task);
316+
317+ // Set thread priority a little higher
318+ BoostThreadPriority(task->mThread);
319+ }
320+ }
321+}
322+
323+#ifdef DEBUG
324+// ZZZ addition (to myTM interface): dump profiling data
325+#define DUMPIT_ZU(structure,field_name) logDump1("" #field_name ":\t%u", (structure).field_name)
326+#define DUMPIT_ZS(structure,field_name) logDump1("" #field_name ":\t%d", (structure).field_name)
327+
328+void
329+myTMDumpProfile(myTMTask* inTask) {
330+ if(inTask != NULL) {
331+ logDump2("PROFILE FOR SDL TMTASK %p (function %p)", inTask, inTask->mFunction);
332+ DUMPIT_ZU((*inTask), mPeriod);
333+ DUMPIT_ZU(inTask->mProfilingData, mStartTime);
334+ DUMPIT_ZU(inTask->mProfilingData, mFinishTime);
335+ DUMPIT_ZU(inTask->mProfilingData, mNumCallsThisReset);
336+ DUMPIT_ZU(inTask->mProfilingData, mNumCallsTotal);
337+ DUMPIT_ZS(inTask->mProfilingData, mDriftMin);
338+ DUMPIT_ZS(inTask->mProfilingData, mDriftMax);
339+ DUMPIT_ZU(inTask->mProfilingData, mNumLateCalls);
340+ DUMPIT_ZU(inTask->mProfilingData, mNumWarmResets);
341+ DUMPIT_ZU(inTask->mProfilingData, mNumResuscitations);
342+ }
343+}
344+#endif//DEBUG
345+
346+// ZZZ addition: clean up outstanding timer task blocks and threads
347+// This could be slightly more efficient maybe by using a list, condensing calls to erase(), etc...
348+// but why bother? It's only used occasionally at non-time-critical moments, and we're only dealing with
349+// a small handful of (small) elements anyway.
350+void
351+myTMCleanup(bool inWaitForFinishers) {
352+ vector<myTMTaskPtr>::iterator i;
353+
354+ for(i = sOutstandingTasks.begin(); i != sOutstandingTasks.end(); ++i) {
355+ if((*i)->mKeepRunning == false && (inWaitForFinishers || (*i)->mIsRunning == false)) {
356+ myTMTaskPtr theDeadTask = *i;
357+
358+ // This does the right thing: i is sent to erase(), but before erase is called, i is decremented so
359+ // the iterator remains valid.
360+ sOutstandingTasks.erase(i--);
361+
362+#ifdef DEBUG
363+ myTMDumpProfile(theDeadTask);
364+#endif
365+
366+ SDL_WaitThread(theDeadTask->mThread, NULL);
367+ delete theDeadTask;
368+ }
369+ }
370+}
--- marathon/trunk/Source_Files/CSeries/mytm_mac_carbon.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/mytm_mac_carbon.cpp (revision 522)
@@ -1,131 +1,131 @@
1-/*
2- * mytm_mac_carbon.cpp
3-
4- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
5- and the "Aleph One" developers.
6-
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 3 of the License, or
10- (at your option) any later version.
11-
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.
16-
17- This license is contained in the file "COPYING",
18- which is included with this source code; it is available online at
19- http://www.gnu.org/licenses/gpl.html
20-
21- Changes:
22-
23-Jan 30, 2000 (Loren Petrich)
24- Did some typecasts
25-
26-Oct 15, 2001 (Woody Zenfell)
27- Renamed this to mytm_macintosh.cpp (from mytm.cpp), so I can also make a mytm_sdl.cpp
28-
29-Jan 25, 2002 (Br'fin (Jeremy Parsons)):
30- Added TARGET_API_MAC_CARBON for Carbon.h
31- timer_proc allocated as a NewTimerUPP under carbon
32-
33-Jan 29, 2002 (Br'fin (Jeremy Parsons)):
34- Forked from mytm_macintosh.cpp to use CarbonEvents timer
35-*/
36-
37-#include <stdlib.h>
38-
39-#include <Carbon/Carbon.h>
40-
41-#include "cstypes.h"
42-#include "csmisc.h"
43-#include "mytm.h"
44-
45-
46-struct myTMTask {
47- EventLoopTimerRef task;
48- bool (*func)(void);
49- long time;
50- bool primed;
51-};
52-
53-static pascal void timer_proc(
54- EventLoopTimerRef inTimer,
55- void *task)
56-{
57- myTMTaskPtr mytask=(myTMTaskPtr)task;
58-
59- mytask->primed=false;
60- if ((*mytask->func)()) {
61- mytask->primed=true;
62- } else {
63- RemoveEventLoopTimer(inTimer);
64- }
65-}
66-
67-static EventLoopTimerUPP timer_upp = NewEventLoopTimerUPP(timer_proc);
68-
69-myTMTaskPtr myTMSetup(
70- int32 time,
71- bool (*func)(void))
72-{
73- myTMTaskPtr result;
74-
75- result= new myTMTask;
76- if (!result)
77- return result;
78- result->func=func;
79- result->time=time;
80- result->primed=true;
81-
82- InstallEventLoopTimer(GetMainEventLoop(),
83- time * kEventDurationMillisecond,
84- time * kEventDurationMillisecond,
85- timer_upp,
86- result,
87- &result->task);
88- return result;
89-}
90-
91-myTMTaskPtr myXTMSetup(
92- int32 time,
93- bool (*func)(void))
94-{
95- return myTMSetup(time, func);
96-}
97-
98-myTMTaskPtr myTMRemove(
99- myTMTaskPtr task)
100-{
101- if (!task)
102- return NULL;
103- if(task->primed)
104- {
105- RemoveEventLoopTimer(task->task);
106- }
107- delete task;
108- return NULL;
109-}
110-
111-void myTMReset(
112- myTMTaskPtr task)
113-{
114- if (task->primed) {
115- SetEventLoopTimerNextFireTime(task->task,
116- task->time * kDurationMillisecond);
117- }
118- else
119- {
120- task->primed=true;
121- InstallEventLoopTimer(GetMainEventLoop(),
122- task->time * kEventDurationMillisecond,
123- task->time * kEventDurationMillisecond,
124- timer_upp,
125- task,
126- &task->task);
127- }
128-}
129-
130-// WZ's dummy function
131-void myTMCleanup(bool) {}
1+/*
2+ * mytm_mac_carbon.cpp
3+
4+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
5+ and the "Aleph One" developers.
6+
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 3 of the License, or
10+ (at your option) any later version.
11+
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.
16+
17+ This license is contained in the file "COPYING",
18+ which is included with this source code; it is available online at
19+ http://www.gnu.org/licenses/gpl.html
20+
21+ Changes:
22+
23+Jan 30, 2000 (Loren Petrich)
24+ Did some typecasts
25+
26+Oct 15, 2001 (Woody Zenfell)
27+ Renamed this to mytm_macintosh.cpp (from mytm.cpp), so I can also make a mytm_sdl.cpp
28+
29+Jan 25, 2002 (Br'fin (Jeremy Parsons)):
30+ Added TARGET_API_MAC_CARBON for Carbon.h
31+ timer_proc allocated as a NewTimerUPP under carbon
32+
33+Jan 29, 2002 (Br'fin (Jeremy Parsons)):
34+ Forked from mytm_macintosh.cpp to use CarbonEvents timer
35+*/
36+
37+#include <stdlib.h>
38+
39+#include <Carbon/Carbon.h>
40+
41+#include "cstypes.h"
42+#include "csmisc.h"
43+#include "mytm.h"
44+
45+
46+struct myTMTask {
47+ EventLoopTimerRef task;
48+ bool (*func)(void);
49+ long time;
50+ bool primed;
51+};
52+
53+static pascal void timer_proc(
54+ EventLoopTimerRef inTimer,
55+ void *task)
56+{
57+ myTMTaskPtr mytask=(myTMTaskPtr)task;
58+
59+ mytask->primed=false;
60+ if ((*mytask->func)()) {
61+ mytask->primed=true;
62+ } else {
63+ RemoveEventLoopTimer(inTimer);
64+ }
65+}
66+
67+static EventLoopTimerUPP timer_upp = NewEventLoopTimerUPP(timer_proc);
68+
69+myTMTaskPtr myTMSetup(
70+ int32 time,
71+ bool (*func)(void))
72+{
73+ myTMTaskPtr result;
74+
75+ result= new myTMTask;
76+ if (!result)
77+ return result;
78+ result->func=func;
79+ result->time=time;
80+ result->primed=true;
81+
82+ InstallEventLoopTimer(GetMainEventLoop(),
83+ time * kEventDurationMillisecond,
84+ time * kEventDurationMillisecond,
85+ timer_upp,
86+ result,
87+ &result->task);
88+ return result;
89+}
90+
91+myTMTaskPtr myXTMSetup(
92+ int32 time,
93+ bool (*func)(void))
94+{
95+ return myTMSetup(time, func);
96+}
97+
98+myTMTaskPtr myTMRemove(
99+ myTMTaskPtr task)
100+{
101+ if (!task)
102+ return NULL;
103+ if(task->primed)
104+ {
105+ RemoveEventLoopTimer(task->task);
106+ }
107+ delete task;
108+ return NULL;
109+}
110+
111+void myTMReset(
112+ myTMTaskPtr task)
113+{
114+ if (task->primed) {
115+ SetEventLoopTimerNextFireTime(task->task,
116+ task->time * kDurationMillisecond);
117+ }
118+ else
119+ {
120+ task->primed=true;
121+ InstallEventLoopTimer(GetMainEventLoop(),
122+ task->time * kEventDurationMillisecond,
123+ task->time * kEventDurationMillisecond,
124+ timer_upp,
125+ task,
126+ &task->task);
127+ }
128+}
129+
130+// WZ's dummy function
131+void myTMCleanup(bool) {}
--- marathon/trunk/Source_Files/CSeries/csfiles.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/csfiles.h (revision 522)
@@ -1,33 +1,33 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-#ifndef _CSERIES_FILES_
22-#define _CSERIES_FILES_
23-
24-extern OSErr get_file_spec(
25- FSSpec *spec,
26- short listid,
27- short item,
28- short pathsid);
29-
30-extern OSErr get_my_fsspec(
31- FSSpec *spec);
32-
33-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+#ifndef _CSERIES_FILES_
22+#define _CSERIES_FILES_
23+
24+extern OSErr get_file_spec(
25+ FSSpec *spec,
26+ short listid,
27+ short item,
28+ short pathsid);
29+
30+extern OSErr get_my_fsspec(
31+ FSSpec *spec);
32+
33+#endif
--- marathon/trunk/Source_Files/CSeries/cspixels.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/cspixels.h (revision 522)
@@ -1,55 +1,55 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-
22-#ifndef _CSERIES_PIXELS_
23-#define _CSERIES_PIXELS_
24-
25-// Need this here
26-#include "cstypes.h"
27-
28-typedef uint8 pixel8;
29-typedef uint16 pixel16;
30-typedef uint32 pixel32;
31-
32-#define PIXEL8_MAXIMUM_COLORS 256
33-#define PIXEL16_MAXIMUM_COMPONENT 31
34-#define PIXEL32_MAXIMUM_COMPONENT 255
35-#define NUMBER_OF_COLOR_COMPONENTS 3
36-
37-/*
38- note that the combiner macros expect input values in the range
39- 0x0000 through 0xFFFF
40- while the extractor macros return output values in the ranges
41- 0x00 through 0x1F (in the 16-bit case)
42- 0x00 through 0xFF (in the 32-bit case)
43- */
44-
45-#define RGBCOLOR_TO_PIXEL16(r,g,b) ((r)>>1&0x7C00 | (g)>>6&0x03E0 | (b)>>11&0x001F)
46-#define RED16(p) ((p)>>10&0x1F)
47-#define GREEN16(p) ((p)>>5&0x1F)
48-#define BLUE16(p) ((p)&0x1F)
49-
50-#define RGBCOLOR_TO_PIXEL32(r,g,b) ((r)<<8&0x00FF0000 | (g)&0x00000FF00 | (b)>>8&0x000000FF)
51-#define RED32(p) ((p)>>16&0xFF)
52-#define GREEN32(p) ((p)>>8&0xFF)
53-#define BLUE32(p) ((p)&0xFF)
54-
55-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+
22+#ifndef _CSERIES_PIXELS_
23+#define _CSERIES_PIXELS_
24+
25+// Need this here
26+#include "cstypes.h"
27+
28+typedef uint8 pixel8;
29+typedef uint16 pixel16;
30+typedef uint32 pixel32;
31+
32+#define PIXEL8_MAXIMUM_COLORS 256
33+#define PIXEL16_MAXIMUM_COMPONENT 31
34+#define PIXEL32_MAXIMUM_COMPONENT 255
35+#define NUMBER_OF_COLOR_COMPONENTS 3
36+
37+/*
38+ note that the combiner macros expect input values in the range
39+ 0x0000 through 0xFFFF
40+ while the extractor macros return output values in the ranges
41+ 0x00 through 0x1F (in the 16-bit case)
42+ 0x00 through 0xFF (in the 32-bit case)
43+ */
44+
45+#define RGBCOLOR_TO_PIXEL16(r,g,b) ((r)>>1&0x7C00 | (g)>>6&0x03E0 | (b)>>11&0x001F)
46+#define RED16(p) ((p)>>10&0x1F)
47+#define GREEN16(p) ((p)>>5&0x1F)
48+#define BLUE16(p) ((p)&0x1F)
49+
50+#define RGBCOLOR_TO_PIXEL32(r,g,b) ((r)<<8&0x00FF0000 | (g)&0x00000FF00 | (b)>>8&0x000000FF)
51+#define RED32(p) ((p)>>16&0xFF)
52+#define GREEN32(p) ((p)>>8&0xFF)
53+#define BLUE32(p) ((p)&0xFF)
54+
55+#endif
--- marathon/trunk/Source_Files/CSeries/snprintf.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/snprintf.cpp (revision 522)
@@ -1,64 +1,64 @@
1-/*
2- * snprintf.h - crude, unsafe imitation of the real snprintf() and vsnprintf()
3-
4- Copyright (C) 2003 and beyond by Woody Zenfell, III
5- and the "Aleph One" developers.
6-
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 3 of the License, or
10- (at your option) any later version.
11-
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.
16-
17- This license is contained in the file "COPYING",
18- which is included with this source code; it is available online at
19- http://www.gnu.org/licenses/gpl.html
20-
21-
22- Jan. 17, 2003 (Woody Zenfell): Created.
23-
24-*/
25-
26-// Build this file in only on platforms that actually need it (Mac OS X, e.g., doesn't)
27-
28-#include "snprintf.h"
29-
30-#include <stdio.h>
31-
32-#include "Logging.h"
33-
34-#ifndef HAVE_SNPRINTF
35-int
36-snprintf(char* inBuffer, size_t inBufferSize, const char* inFormat, ...) {
37- va_list theArgs;
38- va_start(theArgs, inFormat);
39- int theResult = vsnprintf(inBuffer, inBufferSize, inFormat, theArgs);
40- va_end(theArgs);
41- return theResult;
42-}
43-#endif
44-
45-// This could, like, fprintf out to a file and check the file size, or maybe we could
46-// legally lift a whole vsnprintf() implementation from somewhere (GNU std library?)
47-// Anyway at least we'll try to give a warning if we overrun.
48-#ifndef HAVE_VSNPRINTF
49-int
50-vsnprintf(char* inBuffer, size_t inBufferSize, const char* inFormat, va_list inArgs) {
51- int theResult = vsprintf(inBuffer, inFormat, inArgs);
52-
53- // In case logging vsnprintf's a long string, don't warn while warning.
54- static bool issuingWarning = false;
55-
56- if(theResult + 1 > inBufferSize && !issuingWarning) {
57- issuingWarning = true;
58- logWarning2("vsnprintf emulation wrote too many bytes (%d/%d)", theResult + 1, inBufferSize);
59- issuingWarning = false;
60- }
61-
62- return theResult;
63-}
64-#endif // !HAVE_VSNPRINTF
1+/*
2+ * snprintf.h - crude, unsafe imitation of the real snprintf() and vsnprintf()
3+
4+ Copyright (C) 2003 and beyond by Woody Zenfell, III
5+ and the "Aleph One" developers.
6+
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 3 of the License, or
10+ (at your option) any later version.
11+
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.
16+
17+ This license is contained in the file "COPYING",
18+ which is included with this source code; it is available online at
19+ http://www.gnu.org/licenses/gpl.html
20+
21+
22+ Jan. 17, 2003 (Woody Zenfell): Created.
23+
24+*/
25+
26+// Build this file in only on platforms that actually need it (Mac OS X, e.g., doesn't)
27+
28+#include "snprintf.h"
29+
30+#include <stdio.h>
31+
32+#include "Logging.h"
33+
34+#ifndef HAVE_SNPRINTF
35+int
36+snprintf(char* inBuffer, size_t inBufferSize, const char* inFormat, ...) {
37+ va_list theArgs;
38+ va_start(theArgs, inFormat);
39+ int theResult = vsnprintf(inBuffer, inBufferSize, inFormat, theArgs);
40+ va_end(theArgs);
41+ return theResult;
42+}
43+#endif
44+
45+// This could, like, fprintf out to a file and check the file size, or maybe we could
46+// legally lift a whole vsnprintf() implementation from somewhere (GNU std library?)
47+// Anyway at least we'll try to give a warning if we overrun.
48+#ifndef HAVE_VSNPRINTF
49+int
50+vsnprintf(char* inBuffer, size_t inBufferSize, const char* inFormat, va_list inArgs) {
51+ int theResult = vsprintf(inBuffer, inFormat, inArgs);
52+
53+ // In case logging vsnprintf's a long string, don't warn while warning.
54+ static bool issuingWarning = false;
55+
56+ if(theResult + 1 > inBufferSize && !issuingWarning) {
57+ issuingWarning = true;
58+ logWarning2("vsnprintf emulation wrote too many bytes (%d/%d)", theResult + 1, inBufferSize);
59+ issuingWarning = false;
60+ }
61+
62+ return theResult;
63+}
64+#endif // !HAVE_VSNPRINTF
--- marathon/trunk/Source_Files/CSeries/gdspec.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/gdspec.h (revision 522)
@@ -1,55 +1,55 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-
22-
23-#ifndef _CSERIES_GDSPEC_
24-#define _CSERIES_GDSPEC_
25-
26-typedef struct GDSpec {
27- short slot;
28- short flags;
29- short bit_depth;
30- short width;
31- short height;
32-} GDSpec,*GDSpecPtr;
33-
34-extern GDHandle BestDevice(
35- GDSpecPtr spec);
36-extern GDHandle MatchGDSpec(
37- GDSpecPtr spec);
38-extern void SetDepthGDSpec(
39- GDSpecPtr spec);
40-extern void BuildGDSpec(
41- GDSpecPtr spec,
42- GDHandle dev);
43-extern bool HasDepthGDSpec(
44- GDSpecPtr spec);
45-extern bool EqualGDSpec(
46- GDSpecPtr spec1,
47- GDSpecPtr spec2);
48-
49-extern short GetSlotFromGDevice(
50- GDHandle dev);
51-
52-extern void display_device_dialog(
53- GDSpecPtr spec);
54-
55-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+
22+
23+#ifndef _CSERIES_GDSPEC_
24+#define _CSERIES_GDSPEC_
25+
26+typedef struct GDSpec {
27+ short slot;
28+ short flags;
29+ short bit_depth;
30+ short width;
31+ short height;
32+} GDSpec,*GDSpecPtr;
33+
34+extern GDHandle BestDevice(
35+ GDSpecPtr spec);
36+extern GDHandle MatchGDSpec(
37+ GDSpecPtr spec);
38+extern void SetDepthGDSpec(
39+ GDSpecPtr spec);
40+extern void BuildGDSpec(
41+ GDSpecPtr spec,
42+ GDHandle dev);
43+extern bool HasDepthGDSpec(
44+ GDSpecPtr spec);
45+extern bool EqualGDSpec(
46+ GDSpecPtr spec1,
47+ GDSpecPtr spec2);
48+
49+extern short GetSlotFromGDevice(
50+ GDHandle dev);
51+
52+extern void display_device_dialog(
53+ GDSpecPtr spec);
54+
55+#endif
--- marathon/trunk/Source_Files/CSeries/byte_swapping.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/byte_swapping.cpp (revision 522)
@@ -1,63 +1,63 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-*/
21-
22-#include "cseries.h"
23-#include "byte_swapping.h"
24-
25-
26-#ifdef ALEPHONE_LITTLE_ENDIAN
27-
28-// Fieldcount is "int" because it can become negative in the code
29-void byte_swap_memory(
30- void *memory,
31- _bs_field type,
32- int fieldcount)
33-{
34- uint8 *walk;
35- int tmp;
36-
37- walk=(uint8 *)memory;
38- switch (type) {
39- case _2byte:
40- while (fieldcount>0) {
41- tmp=walk[0];
42- walk[0]=walk[1];
43- walk[1]=tmp;
44- walk+=2;
45- fieldcount--;
46- }
47- break;
48- case _4byte:
49- while (fieldcount>0) {
50- tmp=walk[0];
51- walk[0]=walk[3];
52- walk[3]=tmp;
53- tmp=walk[1];
54- walk[1]=walk[2];
55- walk[2]=tmp;
56- walk+=4;
57- fieldcount--;
58- }
59- break;
60- }
61-}
62-
63-#endif
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+
22+#include "cseries.h"
23+#include "byte_swapping.h"
24+
25+
26+#ifdef ALEPHONE_LITTLE_ENDIAN
27+
28+// Fieldcount is "int" because it can become negative in the code
29+void byte_swap_memory(
30+ void *memory,
31+ _bs_field type,
32+ int fieldcount)
33+{
34+ uint8 *walk;
35+ int tmp;
36+
37+ walk=(uint8 *)memory;
38+ switch (type) {
39+ case _2byte:
40+ while (fieldcount>0) {
41+ tmp=walk[0];
42+ walk[0]=walk[1];
43+ walk[1]=tmp;
44+ walk+=2;
45+ fieldcount--;
46+ }
47+ break;
48+ case _4byte:
49+ while (fieldcount>0) {
50+ tmp=walk[0];
51+ walk[0]=walk[3];
52+ walk[3]=tmp;
53+ tmp=walk[1];
54+ walk[1]=walk[2];
55+ walk[2]=tmp;
56+ walk+=4;
57+ fieldcount--;
58+ }
59+ break;
60+ }
61+}
62+
63+#endif
--- marathon/trunk/Source_Files/CSeries/csdialogs.h (revision 521)
+++ marathon/trunk/Source_Files/CSeries/csdialogs.h (revision 522)
@@ -1,262 +1,262 @@
1-/*
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-
21-Sept-Nov 2001 (Woody Zenfell): approximate emulations of originally Mac OS-only routines for
22- the SDL dialog system, lets us share more code. Using API that's a bit more specific, so
23- we can split what were originally single functions into several related ones. Mac OS
24- implementation of these "split" functions is still handled by the original function.
25-
26-Feb 27, 2002 (Br'fin (Jeremy Parsons)):
27- Added utility routine GetListBoxListHandle for Carbon
28-*/
29-
30-#include <string> /* Prefix header doesn't do this? */
31-#include <vector>
32-
33-#ifndef _CSERIES_DIALOGS_
34-#define _CSERIES_DIALOGS_
35-
36-#define iOK 1
37-#define iCANCEL 2
38-
39-#ifdef SDL_RFORK_HACK
40-//AS thinks this is a great hack
41-#define dialog CHEESEOFDEATH
42-#define DialogPtr mDialogPtr
43-#include <Dialogs.h>
44-#undef dialog
45-#undef DialogPtr
46-#endif
47-
48-#if defined(mac)
49-
50-#ifdef USES_NIBS
51-typedef WindowRef DialogPTR;
52-#define CONTROL_INACTIVE 0
53-#define CONTROL_ACTIVE 1
54-#else
55-typedef DialogPtr DialogPTR;
56-#define CONTROL_INACTIVE kControlInactivePart
57-#define CONTROL_ACTIVE kControlNoPart
58-#endif
59-
60-#else //!mac
61-
62-class dialog;
63-
64-typedef dialog* DialogPtr;
65-typedef dialog* DialogPTR;
66-
67-#define CONTROL_INACTIVE 0
68-#define CONTROL_ACTIVE 1
69-
70-#endif //!mac
71-
72-// (jkvw) Prototypes for all platforms, to (hopefully?) get ourselves a usable common interface.
73-
74-extern bool QQ_control_exists (DialogPTR dlg, int item);
75-extern void QQ_set_control_activity (DialogPTR dlg, int item, bool active);
76-extern void QQ_hide_control (DialogPTR dlg, int item);
77-extern void QQ_show_control (DialogPTR dlg, int item);
78-
79-extern bool QQ_get_boolean_control_value (DialogPTR dlg, int item);
80-extern void QQ_set_boolean_control_value (DialogPTR dlg, int item, bool value);
81-
82-extern int QQ_get_selector_control_value (DialogPTR dlg, int item);
83-extern void QQ_set_selector_control_value (DialogPTR dlg, int item, int value);
84-extern void QQ_set_selector_control_labels (DialogPTR dlg, int item, const std::vector<std::string> labels);
85-extern void QQ_set_selector_control_labels_from_stringset (DialogPTR dlg, int item, int stringset_id);
86-
87-extern const std::string QQ_copy_string_from_text_control (DialogPTR dlg, int item);
88-extern void QQ_copy_string_to_text_control (DialogPTR dlg, int item, const std::string &s);
89-extern int32 QQ_extract_number_from_text_control (DialogPTR dlg, int item);
90-extern void QQ_insert_number_into_text_control (DialogPTR dlg, int item, int32 number);
91-
92-
93-// (ZZZ:) Prototypes for both platforms. I think I wrote some of these (on both platforms)
94-// so we could use a common API for common operations. Others I think already existed with
95-// Mac OS implementations, so I just wrote SDL implementations.
96-extern int32 extract_number_from_text_item(
97- DialogPtr dlg,
98- short item);
99-
100-extern void insert_number_into_text_item(
101- DialogPtr dlg,
102- short item,
103- int32 number);
104-
105-extern void copy_pstring_from_text_field(
106- DialogPtr dialog,
107- short item,
108- unsigned char* pstring);
109-
110-extern void copy_pstring_to_text_field(
111- DialogPtr dialog,
112- short item,
113- const unsigned char* pstring);
114-
115-extern void copy_pstring_to_static_text(DialogPtr dialog, short item, const unsigned char* pstring);
116-
117-
118-
119-// (ZZZ:) For Macs only (some more non-Mac stuff later, read on)
120-#ifdef mac
121-#define SCROLLBAR_WIDTH 16
122-
123-enum {
124- centerRect
125-};
126-
127-extern void AdjustRect(
128- Rect const *frame,
129- Rect const *in,
130- Rect *out,
131- short how);
132-
133-extern void get_window_frame(
134- WindowPtr win,
135- Rect *frame);
136-
137-extern DialogPtr myGetNewDialog(
138- short id,
139- void *storage,
140- WindowPtr before,
141- long refcon);
142-
143-extern pascal Boolean general_filter_proc(
144- DialogPtr dlg,
145- EventRecord *event,
146- short *hit);
147-extern ModalFilterUPP get_general_filter_upp(void);
148-
149-extern void set_dialog_cursor_tracking(
150- bool tracking);
151-
152-extern bool hit_dialog_button(
153- DialogPtr dlg,
154- short item);
155-
156-extern short get_dialog_control_value(
157- DialogPtr dialog,
158- short which_control);
159-
160-extern void modify_control(
161- DialogPtr dlg,
162- short item,
163- short hilite,
164- short value);
165-
166-extern void modify_radio_button_family(
167- DialogPtr dlg,
168- short firstItem,
169- short lastItem,
170- short activeItem);
171-
172-typedef void (*dialog_header_proc_ptr)(
173- DialogPtr dialog,
174- Rect *frame);
175-
176-extern void set_dialog_header_proc(
177- dialog_header_proc_ptr proc);
178-
179-#endif//mac
180-
181-
182-
183-// (ZZZ:) Now, some functions I "specialized" for SDL are simply forwarded to the original, more
184-// general versions on classic Mac...
185-// These more specific names show better what manipulation is desired. Also, more importantly,
186-// they let us patch up some differences between the way the Mac OS handles things and the way
187-// Christian's dialog code handles things (e.g., a Mac OS selection control (popup) is numbered
188-// from 1, whereas a boolean control (checkbox) is numbered 0 or 1. In Christian's code, all
189-// selection controls (w_select and subclasses, including the boolean control w_toggle) are
190-// indexed from 0).
191-// These functions use the Mac OS numbering scheme.
192-#ifdef mac
193-__inline__ void modify_selection_control(
194- DialogPtr dlg,
195- short item,
196- short hilite,
197- short value) {modify_control(dlg, item, hilite, value); }
198-
199-__inline__ void modify_control_enabled(
200- DialogPtr dlg,
201- short item,
202- short hilite) {modify_control(dlg, item, hilite, NONE); }
203-
204-__inline__ void modify_boolean_control(
205- DialogPtr dlg,
206- short item,
207- short hilite,
208- short value) {modify_control(dlg, item, hilite, value); }
209-
210-__inline__ short get_selection_control_value(
211- DialogPtr dialog,
212- short which_control) {return get_dialog_control_value(dialog, which_control); }
213-
214-__inline__ bool get_boolean_control_value(
215- DialogPtr dialog,
216- short which_control) {return get_dialog_control_value(dialog, which_control); }
217-
218-#else//!mac
219-
220-// (ZZZ: Here are the prototypes for the specialized SDL versions.)
221-extern void modify_selection_control(
222- DialogPtr dlg,
223- short item,
224- short hilite,
225- short value);
226-
227-extern void modify_control_enabled(
228- DialogPtr dlg,
229- short item,
230- short hilite);
231-
232-extern void modify_boolean_control(
233- DialogPtr dlg,
234- short item,
235- short hilite,
236- short value);
237-
238-extern short get_selection_control_value(
239- DialogPtr dialog,
240- short which_control);
241-
242-extern bool get_boolean_control_value(
243- DialogPtr dialog,
244- short which_control);
245-#endif//!mac
246-
247-
248-
249-// ZZZ: (very) approximate SDL emulation of Mac OS Toolbox routines - see note in implementation
250-#ifndef mac
251-void HideDialogItem(DialogPtr dialog, short item_index);
252-void ShowDialogItem(DialogPtr dialog, short item_index);
253-#endif // !mac
254-
255-#if defined(TARGET_API_MAC_CARBON)
256-#ifndef SDL
257-// JTP: Get the list manager handle for a listbox control
258-pascal OSStatus GetListBoxListHandle( ControlHandle control, ListHandle* list );
259-#endif
260-#endif
261-
262-#endif//_CSERIES_DIALOGS_
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+
21+Sept-Nov 2001 (Woody Zenfell): approximate emulations of originally Mac OS-only routines for
22+ the SDL dialog system, lets us share more code. Using API that's a bit more specific, so
23+ we can split what were originally single functions into several related ones. Mac OS
24+ implementation of these "split" functions is still handled by the original function.
25+
26+Feb 27, 2002 (Br'fin (Jeremy Parsons)):
27+ Added utility routine GetListBoxListHandle for Carbon
28+*/
29+
30+#include <string> /* Prefix header doesn't do this? */
31+#include <vector>
32+
33+#ifndef _CSERIES_DIALOGS_
34+#define _CSERIES_DIALOGS_
35+
36+#define iOK 1
37+#define iCANCEL 2
38+
39+#ifdef SDL_RFORK_HACK
40+//AS thinks this is a great hack
41+#define dialog CHEESEOFDEATH
42+#define DialogPtr mDialogPtr
43+#include <Dialogs.h>
44+#undef dialog
45+#undef DialogPtr
46+#endif
47+
48+#if defined(mac)
49+
50+#ifdef USES_NIBS
51+typedef WindowRef DialogPTR;
52+#define CONTROL_INACTIVE 0
53+#define CONTROL_ACTIVE 1
54+#else
55+typedef DialogPtr DialogPTR;
56+#define CONTROL_INACTIVE kControlInactivePart
57+#define CONTROL_ACTIVE kControlNoPart
58+#endif
59+
60+#else //!mac
61+
62+class dialog;
63+
64+typedef dialog* DialogPtr;
65+typedef dialog* DialogPTR;
66+
67+#define CONTROL_INACTIVE 0
68+#define CONTROL_ACTIVE 1
69+
70+#endif //!mac
71+
72+// (jkvw) Prototypes for all platforms, to (hopefully?) get ourselves a usable common interface.
73+
74+extern bool QQ_control_exists (DialogPTR dlg, int item);
75+extern void QQ_set_control_activity (DialogPTR dlg, int item, bool active);
76+extern void QQ_hide_control (DialogPTR dlg, int item);
77+extern void QQ_show_control (DialogPTR dlg, int item);
78+
79+extern bool QQ_get_boolean_control_value (DialogPTR dlg, int item);
80+extern void QQ_set_boolean_control_value (DialogPTR dlg, int item, bool value);
81+
82+extern int QQ_get_selector_control_value (DialogPTR dlg, int item);
83+extern void QQ_set_selector_control_value (DialogPTR dlg, int item, int value);
84+extern void QQ_set_selector_control_labels (DialogPTR dlg, int item, const std::vector<std::string> labels);
85+extern void QQ_set_selector_control_labels_from_stringset (DialogPTR dlg, int item, int stringset_id);
86+
87+extern const std::string QQ_copy_string_from_text_control (DialogPTR dlg, int item);
88+extern void QQ_copy_string_to_text_control (DialogPTR dlg, int item, const std::string &s);
89+extern int32 QQ_extract_number_from_text_control (DialogPTR dlg, int item);
90+extern void QQ_insert_number_into_text_control (DialogPTR dlg, int item, int32 number);
91+
92+
93+// (ZZZ:) Prototypes for both platforms. I think I wrote some of these (on both platforms)
94+// so we could use a common API for common operations. Others I think already existed with
95+// Mac OS implementations, so I just wrote SDL implementations.
96+extern int32 extract_number_from_text_item(
97+ DialogPtr dlg,
98+ short item);
99+
100+extern void insert_number_into_text_item(
101+ DialogPtr dlg,
102+ short item,
103+ int32 number);
104+
105+extern void copy_pstring_from_text_field(
106+ DialogPtr dialog,
107+ short item,
108+ unsigned char* pstring);
109+
110+extern void copy_pstring_to_text_field(
111+ DialogPtr dialog,
112+ short item,
113+ const unsigned char* pstring);
114+
115+extern void copy_pstring_to_static_text(DialogPtr dialog, short item, const unsigned char* pstring);
116+
117+
118+
119+// (ZZZ:) For Macs only (some more non-Mac stuff later, read on)
120+#ifdef mac
121+#define SCROLLBAR_WIDTH 16
122+
123+enum {
124+ centerRect
125+};
126+
127+extern void AdjustRect(
128+ Rect const *frame,
129+ Rect const *in,
130+ Rect *out,
131+ short how);
132+
133+extern void get_window_frame(
134+ WindowPtr win,
135+ Rect *frame);
136+
137+extern DialogPtr myGetNewDialog(
138+ short id,
139+ void *storage,
140+ WindowPtr before,
141+ long refcon);
142+
143+extern pascal Boolean general_filter_proc(
144+ DialogPtr dlg,
145+ EventRecord *event,
146+ short *hit);
147+extern ModalFilterUPP get_general_filter_upp(void);
148+
149+extern void set_dialog_cursor_tracking(
150+ bool tracking);
151+
152+extern bool hit_dialog_button(
153+ DialogPtr dlg,
154+ short item);
155+
156+extern short get_dialog_control_value(
157+ DialogPtr dialog,
158+ short which_control);
159+
160+extern void modify_control(
161+ DialogPtr dlg,
162+ short item,
163+ short hilite,
164+ short value);
165+
166+extern void modify_radio_button_family(
167+ DialogPtr dlg,
168+ short firstItem,
169+ short lastItem,
170+ short activeItem);
171+
172+typedef void (*dialog_header_proc_ptr)(
173+ DialogPtr dialog,
174+ Rect *frame);
175+
176+extern void set_dialog_header_proc(
177+ dialog_header_proc_ptr proc);
178+
179+#endif//mac
180+
181+
182+
183+// (ZZZ:) Now, some functions I "specialized" for SDL are simply forwarded to the original, more
184+// general versions on classic Mac...
185+// These more specific names show better what manipulation is desired. Also, more importantly,
186+// they let us patch up some differences between the way the Mac OS handles things and the way
187+// Christian's dialog code handles things (e.g., a Mac OS selection control (popup) is numbered
188+// from 1, whereas a boolean control (checkbox) is numbered 0 or 1. In Christian's code, all
189+// selection controls (w_select and subclasses, including the boolean control w_toggle) are
190+// indexed from 0).
191+// These functions use the Mac OS numbering scheme.
192+#ifdef mac
193+__inline__ void modify_selection_control(
194+ DialogPtr dlg,
195+ short item,
196+ short hilite,
197+ short value) {modify_control(dlg, item, hilite, value); }
198+
199+__inline__ void modify_control_enabled(
200+ DialogPtr dlg,
201+ short item,
202+ short hilite) {modify_control(dlg, item, hilite, NONE); }
203+
204+__inline__ void modify_boolean_control(
205+ DialogPtr dlg,
206+ short item,
207+ short hilite,
208+ short value) {modify_control(dlg, item, hilite, value); }
209+
210+__inline__ short get_selection_control_value(
211+ DialogPtr dialog,
212+ short which_control) {return get_dialog_control_value(dialog, which_control); }
213+
214+__inline__ bool get_boolean_control_value(
215+ DialogPtr dialog,
216+ short which_control) {return get_dialog_control_value(dialog, which_control); }
217+
218+#else//!mac
219+
220+// (ZZZ: Here are the prototypes for the specialized SDL versions.)
221+extern void modify_selection_control(
222+ DialogPtr dlg,
223+ short item,
224+ short hilite,
225+ short value);
226+
227+extern void modify_control_enabled(
228+ DialogPtr dlg,
229+ short item,
230+ short hilite);
231+
232+extern void modify_boolean_control(
233+ DialogPtr dlg,
234+ short item,
235+ short hilite,
236+ short value);
237+
238+extern short get_selection_control_value(
239+ DialogPtr dialog,
240+ short which_control);
241+
242+extern bool get_boolean_control_value(
243+ DialogPtr dialog,
244+ short which_control);
245+#endif//!mac
246+
247+
248+
249+// ZZZ: (very) approximate SDL emulation of Mac OS Toolbox routines - see note in implementation
250+#ifndef mac
251+void HideDialogItem(DialogPtr dialog, short item_index);
252+void ShowDialogItem(DialogPtr dialog, short item_index);
253+#endif // !mac
254+
255+#if defined(TARGET_API_MAC_CARBON)
256+#ifndef SDL
257+// JTP: Get the list manager handle for a listbox control
258+pascal OSStatus GetListBoxListHandle( ControlHandle control, ListHandle* list );
259+#endif
260+#endif
261+
262+#endif//_CSERIES_DIALOGS_
--- marathon/trunk/Source_Files/CSeries/csdialogs_macintosh.cpp (revision 521)
+++ marathon/trunk/Source_Files/CSeries/csdialogs_macintosh.cpp (revision 522)
@@ -1,1391 +1,1391 @@
1-/* csdialogs_macintosh.cpp
2-
3- Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4- and the "Aleph One" developers.
5-
6- This program is free software; you can redistribute it and/or modify
7- it under the terms of the GNU General Public License as published by
8- the Free Software Foundation; either version 3 of the License, or
9- (at your option) any later version.
10-
11- This program is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- GNU General Public License for more details.
15-
16- This license is contained in the file "COPYING",
17- which is included with this source code; it is available online at
18- http://www.gnu.org/licenses/gpl.html
19-
20-
21- Sept-Nov 2001 (Woody Zenfell):
22- renamed from csdialogs.cpp
23- inserted get_dialog_control_value, from network_dialogs.cpp
24- new functions copy_pstring_*_text_field()
25-
26-Jan 25, 2002 (Br'fin (Jeremy Parsons)):
27- Added TARGET_API_MAC_CARBON for Carbon.h
28- Added accessors for datafields now opaque in Carbon
29-
30-Feb 3, 2002 (Br'fin (Jeremy Parsons)):
31- For carbon, replaced framing of our own group boxes with a theme seperator line at the top
32-
33-Feb 27, 2002 (Br'fin (Jeremy Parsons)):
34- Adjusted modify_control to call the recommended De/ActivateControl
35- for controls in a control hierarchy under Carbon
36- Added utility routine GetListBoxListHandle for Carbon
37-*/
38-
39-#if defined(EXPLICIT_CARBON_HEADER)
40- #include <Carbon/Carbon.h>
41-/*
42-#else
43-#include <Dialogs.h>
44-#include <TextUtils.h>
45-*/
46-#endif
47-
48-#include "cstypes.h"
49-#include "csdialogs.h"
50-#include "csmacros.h"
51-#include "csstrings.h"
52-#include "TextStrings.h"
53-
54-extern void update_any_window(
55- WindowPtr window,
56- EventRecord *event);
57-extern void activate_any_window(
58- WindowPtr window,
59- EventRecord *event,
60- bool active);
61-
62-static bool cursor_tracking=true;
63-static dialog_header_proc_ptr header_proc;
64-static OSErr get_handle_for_dialog_item(DialogPtr, short, Handle *);
65-
66-DialogPtr myGetNewDialog(
67- short id,
68- void *storage,
69- WindowPtr before,
70- long refcon)
71-{
72- DialogPtr dlg;
73- short it;
74- Handle ih;
75- Rect ir;
76-
77- dlg=GetNewDialog(id,storage,before);
78- if (dlg) {
79- SetWRefCon(GetDialogWindow(dlg),refcon);
80- GetDialogItem(dlg,iOK,&it,&ih,&ir);
81- if (it==kButtonDialogItem) {
82- SetDialogDefaultItem(dlg,iOK);
83- GetDialogItem(dlg,iCANCEL,&it,&ih,&ir);
84- if (it==kButtonDialogItem)
85- SetDialogCancelItem(dlg,iCANCEL);
86- }
87- }
88- return dlg;
89-}
90-
91-static RGBColor third={0x5555,0x5555,0x5555};
92-
93-static void frame_useritems(
94- DialogPtr dlg)
95-{
96- RgnHandle outer,inner,good,bad;
97- int i,n;
98- short it;
99- Handle ih;
100- Rect ir;
101- Boolean fillRegion = false;
102-
103- good=NewRgn();
104- bad=NewRgn();
105- outer=NewRgn();
106- inner=NewRgn();
107- n=CountDITL(dlg);
108- for (i=1; i<=n; i++) {
109- GetDialogItem(dlg,i,&it,&ih,&ir);
110- if ((it&~kItemDisableBit)==kUserDialogItem && !ih) {
111-#if defined(TARGET_API_MAC_CARBON)
112- /*
113- * A user item with no drawing proc installed is assumed to be a group box.
114- * Use the appearance manager to draw a seperator line at the top of the group
115- */
116- // And keep it from being painted over
117- RectRgn(outer,&ir);
118- UnionRgn(bad,outer,bad);
119-
120- ThemeDrawState curState =
121- IsWindowActive(GetDialogWindow(dlg))?kThemeStateActive:kThemeStateInactive;
122-
123- ir.bottom = ir.top + 2;
124- ir.left += 10;
125-
126- DrawThemeSeparator(&ir, curState);
127-#else
128- /*
129- * A user item with no drawing proc installed is assumed to be a group box.
130- * Make a 1-pixel-thick frame from its rect and add it to the region to paint.
131- */
132- RectRgn(outer,&ir);
133- CopyRgn(outer,inner);
134- InsetRgn(inner,1,1);
135- DiffRgn(outer,inner,outer);
136- UnionRgn(good,outer,good);
137-#endif
138- } else {
139- /*
140- * For all other items, add its rect to the region _not_ to paint.
141- */
142- RectRgn(outer,&ir);
143- UnionRgn(bad,outer,bad);
144- }
145- }
146- DisposeRgn(inner);
147- DisposeRgn(outer);
148- DiffRgn(good,bad,good);
149- DisposeRgn(bad);
150- if(fillRegion)
151- {
152- RGBForeColor(&third);
153- PaintRgn(good);
154- }
155- ForeColor(blackColor);
156- DisposeRgn(good);
157-}
158-
159-pascal Boolean general_filter_proc(
160- DialogPtr dlg,
161- EventRecord *event,
162- short *hit)
163-{
164- WindowPtr win;
165- Rect frame;
166- GrafPtr saveport;
167-
168- GetPort(&saveport);
169- SetDialogTracksCursor(dlg,cursor_tracking);
170- switch (event->what) {
171- case updateEvt:
172- win=(WindowPtr)event->message;
173- SetPort(GetWindowPort(win));
174- if (GetWindowKind(win)==kDialogWindowKind) {
175- if (header_proc) {
176- GetPortBounds(GetWindowPort(GetDialogWindow(dlg)), &frame);
177- (*header_proc)(GetDialogFromWindow(win),&frame);
178- }
179- frame_useritems(dlg);
180- } else {
181- update_any_window(win,event);
182- }
183- break;
184- case activateEvt:
185- win=(WindowPtr)event->message;
186- if (GetWindowKind(win)!=kDialogWindowKind)
187- activate_any_window(win,event,(event->modifiers&activeFlag)!=0);
188- break;
189- }
190- SetPort(saveport);
191- return StdFilterProc(dlg,event,hit);
192-}
193-
194-#if defined(TARGET_API_MAC_CARBON)
195-ModalFilterUPP general_filter_upp = NewModalFilterUPP(general_filter_proc);
196-#else
197-#if GENERATINGCFM
198-static RoutineDescriptor general_filter_desc =
199- BUILD_ROUTINE_DESCRIPTOR(uppModalFilterProcInfo,general_filter_proc);
200-#define general_filter_upp (&general_filter_desc)
201-#else
202-#define general_filter_upp general_filter_proc
203-#endif
204-#endif
205-
206-ModalFilterUPP get_general_filter_upp(void)
207-{
208- return general_filter_upp;
209-}
210-
211-void set_dialog_cursor_tracking(
212- bool tracking)
213-{
214- cursor_tracking=tracking;
215-}
216-
217-int32 extract_number_from_text_item(
218- DialogPtr dlg,
219- short item)
220-{
221- Str255 str;
222- int32 num;
223- Handle ih;
224-
225- get_handle_for_dialog_item(dlg, item, &ih);
226- GetDialogItemText(ih,str);
227- StringToNum(str,&num);
228- return num;
229-}
230-
231-void insert_number_into_text_item(
232- DialogPtr dlg,
233- short item,
234- int32 number)
235-{
236- Str255 str;
237- Handle ih;
238-
239- NumToString(number,str);
240- get_handle_for_dialog_item(dlg, item, &ih);
241- SetDialogItemText(ih,str);
242-}
243-
244-bool hit_dialog_button(
245- DialogPtr dlg,
246- short item)
247-{
248- short it;
249- Handle ih;
250- Rect ir;
251- ControlHandle button;
252- unsigned long ignore;
253-
254- GetDialogItem(dlg,item,&it,&ih,&ir);
255- if (it!=kButtonDialogItem)
256- return false;
257- button=(ControlHandle)ih;
258- if (GetControlHilite(button)!=kControlNoPart)
259- return false;
260- HiliteControl(button,kControlButtonPart);
261- Delay(8,&ignore);
262- HiliteControl(button,kControlNoPart);
263- return true;
264-}
265-
266-void modify_control(
267- DialogPtr dlg,
268- short item,
269- short hilite,
270- short value)
271-{
272- short it;
273- Handle ih;
274- Rect ir;
275- ControlHandle control;
276-
277- GetDialogItem(dlg,item,&it,&ih,&ir);
278- control=(ControlHandle)ih;
279-#if TARGET_API_MAC_CARBON
280- if (hilite!=NONE)
281- {
282- // JTP: This works well for non-buttons, such as labels and edit text boxes
283- // but is useless without a control hierarchy enabled, so we fall back to the old ways
284- ControlRef hierarchyControl;
285- if((hilite == CONTROL_INACTIVE || hilite == CONTROL_ACTIVE)
286- && (GetDialogItemAsControl( dlg, item, &hierarchyControl ) == noErr))
287- {
288- if(hilite == CONTROL_INACTIVE)
289- #ifdef __MACH__
290- DisableControl(hierarchyControl);
291- #else
292- DeactivateControl(hierarchyControl);
293- #endif
294- else
295- #ifdef __MACH__
296- EnableControl(hierarchyControl);
297- #else
298- ActivateControl(hierarchyControl);
299- #endif
300- }
301- else
302- HiliteControl(control,hilite);
303- }
304-#else
305- if (hilite!=NONE)
306- HiliteControl(control,hilite);
307-#endif
308- if (value!=NONE)
309- SetControlValue(control,value);
310-}
311-
312-void modify_radio_button_family(
313- DialogPtr dlg,
314- short firstItem,
315- short lastItem,
316- short activeItem)
317-{
318- int item;
319- short it;
320- Handle ih;
321- Rect ir;
322- ControlHandle control;
323- int value;
324-
325- for (item=firstItem; item<=lastItem; item++) {
326- GetDialogItem(dlg,item,&it,&ih,&ir);
327- control=(ControlHandle)ih;
328- if (item==activeItem) {
329- value=kControlRadioButtonCheckedValue;
330- } else {
331- value=kControlRadioButtonUncheckedValue;
332- }
333- SetControlValue(control,value);
334- }
335-}
336-
337-void set_dialog_header_proc(
338- dialog_header_proc_ptr proc)
339-{
340- header_proc=proc;
341-}
342-
343-void AdjustRect(
344- Rect const *frame,
345- Rect const *in,
346- Rect *out,
347- short how)
348-{
349- int dim;
350-
351- switch (how) {
352- case centerRect:
353- dim=in->right-in->left;
354- out->left=(frame->left+frame->right-dim)/2;
355- out->right=out->left+dim;
356- dim=in->bottom-in->top;
357- out->top=(frame->top+frame->bottom-dim)/2;
358- out->bottom=out->top+dim;
359- break;
360- }
361-}
362-
363-void get_window_frame(
364- WindowPtr win,
365- Rect *frame)
366-{
367- GrafPtr saveport;
368- Rect pr;
369-
370- GetPort(&saveport);
371- SetPort(GetWindowPort(win));
372- GetPortBounds(GetWindowPort(win), &pr);
373- LocalToGlobal((Point *)&pr.top);
374- LocalToGlobal((Point *)&pr.bottom);
375- SetPort(saveport);
376- *frame=pr;
377-}
378-
379-// ZZZ: added these to parallel SDL version. Now we have a common interface.
380-void
381-copy_pstring_from_text_field(DialogPtr dialog, short item, unsigned char* pstring) {
382- Handle item_handle;
383-
384- get_handle_for_dialog_item(dialog, item, &item_handle);
385- GetDialogItemText(item_handle, pstring);
386-}
387-
388-void
389-copy_pstring_to_text_field(DialogPtr dialog, short item, const unsigned char* pstring) {
390- Handle item_handle;
391-
392- get_handle_for_dialog_item(dialog, item, &item_handle);
393- SetDialogItemText(item_handle, pstring);
394-}
395-
396-void
397-copy_pstring_to_static_text(DialogPtr dialog, short item, const unsigned char* pstring) {
398- Handle item_handle;
399-
400- get_handle_for_dialog_item(dialog, item, &item_handle);
401- SetDialogItemText(item_handle, pstring);
402-}
403-// ZZZ: moved here from network_dialogs_macintosh.cpp
404-short get_dialog_control_value(DialogPtr dialog, short which_control)
405-{
406- Rect item_rect;
407- short item_type;
408- Handle item_handle;
409-
410- GetDialogItem(dialog, which_control, &item_type, &item_handle, &item_rect);
411- return GetControlValue((ControlHandle) item_handle);
412-}
413-
414-#ifndef mac
415-
416-// ZZZ: added these to inject a layer of indirection to slip in an SDL implementation and have the two versions share
417-void
418-copy_pstring_from_text_field(DialogPtr dialog, short item, unsigned char* pstring) {
419- Rect item_rect;
420- short item_type;
421- Handle item_handle;
422-
423- GetDialogItem(dialog, item, &item_type, &item_handle, &item_rect);
424- GetDialogItemText(item_handle, pstring);
425-}
426-
427-void
428-copy_pstring_to_text_field(DialogPtr dialog, short item, const unsigned char* pstring) {
429- Rect item_rect;
430- short item_type;
431- Handle item_handle;
432-
433- GetDialogItem(dialog, item, &item_type, &item_handle, &item_rect);
434- SetDialogItemText(item_handle, pstring);
435-}
436-
437-#endif
438-
439-static OSErr get_handle_for_dialog_item(DialogPtr __dialog, short __item, Handle *__handle)
440-{
441- ControlRef control_ref;
442- // If control embedding is turned on, then use appropriate variants
443- if(GetDialogItemAsControl(__dialog, __item, &control_ref) == noErr)
444- {
445- *__handle= reinterpret_cast<Handle>(control_ref);
446- } else {
447- Rect item_rect;
448- short item_type;
449- Handle item_handle;
450-
451- GetDialogItem(__dialog, __item, &item_type, &item_handle, &item_rect);
452- *__handle= item_handle;
453- }
454- return noErr;
455-}
456-
457-#if TARGET_API_MAC_CARBON
458-// JTP: Taken from an AppearanceManager code sample
459-//ムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムム
460-// ・ GetListBoxListHandle
461-//ムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムム
462-// Returns the list handle from a list box control.
463-//
464-pascal OSStatus
465-GetListBoxListHandle( ControlHandle control, ListHandle* list )
466-{
467- Size actualSize;
468- OSStatus err;
469-
470- if ( control == nil )
471- return paramErr;
472-
473- if ( list == nil )
474- return paramErr;
475-
476- err = GetControlData( control, 0, kControlListBoxListHandleTag, sizeof( ListHandle ),
477- (Ptr)list, &actualSize );
478-
479- return err;
480-}
481-#endif
482-
483-
484-#include "csalerts.h"
485-#include <stdio.h>
486-#include <string.h>
487-#include "NibsUiHelpers.h"
488-
489-static OSType global_signature = 0;
490-
491-std::auto_ptr<SelfReleasingCFStringRef>
492-StringToCFString(const std::string& s)
493-{
494- return std::auto_ptr<SelfReleasingCFStringRef>(
495- new SelfReleasingCFStringRef(
496- CFStringCreateWithCString(NULL, s.c_str(), kCFStringEncodingMacRoman)
497- )
498- );
499-}
500-
501-
502-
503-AutoNibWindow::AutoNibWindow(IBNibRef Nib, CFStringRef Name)
504-{
505- OSStatus err;
506-
507- err = CreateWindowFromNib(Nib,Name,&w);
508-
509- const int BufferSize = 192; // Smaller than 256, the size of "temporary"
510- char Buffer[BufferSize];
511- if (err != noErr)
512- {
513- CFStringGetCString(Name, Buffer, BufferSize, kCFStringEncodingMacRoman);
514- Buffer[BufferSize-1] = 0; // Null terminator byte
515- }
516- vassert(err == noErr,
517- csprintf(temporary,"CreateWindowFromNib error: %d for window %s",(int)err,Buffer));
518-}
519-
520-
521-AutoNibWindow::~AutoNibWindow() {DisposeWindow(w);}
522-
523-
524-ControlRef GetCtrlFromWindow(WindowRef DlgWindow, uint32 Signature, uint32 ID)
525-{
526- OSStatus err;
527-
528- // Set up the popup menu
529- ControlID CtrlID;
530- CtrlID.signature = Signature;
531- CtrlID.id = ID;
532-
533- ControlRef Ctrl;
534- err = GetControlByID(DlgWindow,&CtrlID,&Ctrl);
535- vassert(err == noErr, csprintf(temporary,"GetControlByID error for sig and id: %d - %d %d",(int)err,(int)Signature,(int)ID));
536- assert(Ctrl);
537-
538- return Ctrl;
539-}
540-
541-
542-void SetControlActivity(ControlRef Ctrl, bool Activity)
543-{
544-
545-#ifdef __MACH__
546- if(Activity)
547- EnableControl(Ctrl);
548- else
549- DisableControl(Ctrl);
550-#else
551- if(Activity)
552- ActivateControl(Ctrl);
553- else
554- DeactivateControl(Ctrl);
555-#endif
556-}
557-
558-void GetStaticPascalText(ControlRef Ctrl, Str255 Text, int MaxLen)
559-{
560- const int BufferLen = 255;
561- char Buffer[BufferLen];
562- Size ActualLen = 0;
563-
564- GetControlData(Ctrl,
565- kControlLabelPart,
566- kControlStaticTextTextTag,
567- BufferLen,
568- Buffer,
569- &ActualLen
570- );
571-
572- if (MaxLen < ActualLen) ActualLen = MaxLen;
573- Text[0] = ActualLen;
574- memcpy(Text+1,Buffer,ActualLen);
575-}
576-
577-void SetStaticPascalText(ControlRef Ctrl, ConstStr255Param Text)
578-{
579- SetControlData(Ctrl,
580- kControlLabelPart,
581- kControlStaticTextTextTag,
582- Text[0],
583- Text+1
584- );
585-}
586-
587-void GetStaticCText(ControlRef Ctrl, char *Text, int MaxLen)
588-{
589- const int BufferLen = 255;
590- char Buffer[BufferLen];
591- Size ActualLen = 0;
592-
593- GetControlData(Ctrl,
594- kControlLabelPart,
595- kControlStaticTextTextTag,
596- BufferLen,
597- Buffer,
598- &ActualLen
599- );
600-
601- if (MaxLen < ActualLen) ActualLen = MaxLen;
602- Text[ActualLen] = 0;
603- memcpy(Text,Buffer,ActualLen);
604-}
605-
606-void SetStaticCText(ControlRef Ctrl, const char *Text)
607-{
608- SetControlData(Ctrl,
609- kControlLabelPart,
610- kControlStaticTextTextTag,
611- strlen(Text),
612- Text
613- );
614-}
615-
616-void GetEditPascalText(ControlRef Ctrl, Str255 Text, int MaxLen)
617-{
618- const int BufferLen = 255;
619- char Buffer[BufferLen];
620- Size ActualLen = 0;
621-
622- GetControlData(Ctrl,
623- kControlEditTextPart,
624- kControlEditTextTextTag,
625- BufferLen,
626- Buffer,
627- &ActualLen
628- );
629-
630- if (MaxLen < ActualLen) ActualLen = MaxLen;
631- Text[0] = ActualLen;
632- memcpy(Text+1,Buffer,ActualLen);
633-}
634-
635-void SetEditPascalText(ControlRef Ctrl, ConstStr255Param Text)
636-{
637- SetControlData(Ctrl,
638- kControlEditTextPart,
639- kControlEditTextTextTag,
640- Text[0],
641- Text+1
642- );
643-}
644-
645-void GetEditCText(ControlRef Ctrl, char *Text, int MaxLen)
646-{
647- const int BufferLen = 255;
648- char Buffer[BufferLen];
649- Size ActualLen = 0;
650-
651- GetControlData(Ctrl,
652- kControlEditTextPart,
653- kControlEditTextTextTag,
654- BufferLen,
655- Buffer,
656- &ActualLen
657- );
658-
659- if (MaxLen < ActualLen) ActualLen = MaxLen;
660- Text[ActualLen] = 0;
661- memcpy(Text,Buffer,ActualLen);
662-}
663-
664-void SetEditCText(ControlRef Ctrl, const char *Text)
665-{
666- SetControlData(Ctrl,
667- kControlEditTextPart,
668- kControlEditTextTextTag,
669- strlen(Text),
670- Text
671- );
672-}
673-
674-void SetGlobalControlSignature(OSType sig)
675-{
676- global_signature = sig;
677-}
678-
679-
680-// Will not support any fancy hit testing;
681-// a user-defined control will effectively be one object
682-const int UserControlPart = 1;
683-
684-const OSType AppTag = 'this';
685-const OSType DrawTag = 'draw';
686-
687-
688-struct ControlDrawerData
689-{
690- void (*DrawFunction)(ControlRef, void *);
691- void *DrawData;
692-};
693-
694-
695-static pascal void ControlDrawer(ControlRef Ctrl, short Part)
696-{
697- OSStatus err;
698- unsigned long ActualSize;
699- ControlDrawerData CtrlDD;
700-
701- err = GetControlProperty(Ctrl,
702- AppTag, DrawTag,
703- sizeof(CtrlDD), &ActualSize, &CtrlDD);
704- vassert(err == noErr, csprintf(temporary,"GetControlProperty error: %d",(int)err));
705-
706- assert(CtrlDD.DrawFunction);
707- CtrlDD.DrawFunction(Ctrl,CtrlDD.DrawData);
708-}
709-
710-
711-AutoDrawability::AutoDrawability()
712-{
713- DrawingUPP = NewControlUserPaneDrawUPP(ControlDrawer);
714-}
715-
716-AutoDrawability::~AutoDrawability()
717-{
718- DisposeControlUserPaneDrawUPP(DrawingUPP);
719-}
720-
721-void AutoDrawability::operator()(ControlRef Ctrl,
722- void (*DrawFunction)(ControlRef, void *),
723- void *DrawData)
724-{
725- OSStatus err;
726-
727- ControlDrawerData CtrlDD;
728-
729- CtrlDD.DrawFunction = DrawFunction;
730- CtrlDD.DrawData = DrawData;
731-
732- err = SetControlData(
733- Ctrl, 0,
734- kControlUserPaneDrawProcTag,
735- sizeof(DrawingUPP), &DrawingUPP
736- );
737- vassert(err == noErr, csprintf(temporary,"SetControlData error: %d",(int)err));
738-
739- err = SetControlProperty(
740- Ctrl,
741- AppTag, DrawTag,
742- sizeof(CtrlDD), &CtrlDD
743- );
744- vassert(err == noErr, csprintf(temporary,"SetControlProperty error: %d",(int)err));
745-}
746-
747-
748-void SwatchDrawer(ControlRef Ctrl, void *Data)
749-{
750- RGBColor *SwatchColorPtr = (RGBColor *)(Data);
751-
752- // No need for the window context -- it's assumed
753- Rect Bounds = {0,0,0,0};
754-
755- GetControlBounds(Ctrl, &Bounds);
756-
757- // Get ready to draw the swatch
758- PenNormal();
759-
760- // Draw!
761- RGBForeColor(SwatchColorPtr);
762- PaintRect(&Bounds);
763- ForeColor(blackColor);
764- FrameRect(&Bounds);
765-}
766-
767-
768-// Globals the most convenient mechanism here,
769-// since an int32 is NOT a void * (generic pointer)
770-static ControlRef PickCtrl;
771-static RGBColor *PickClrPtr;
772-
773-
774-static pascal void PickColorChangedFunc(int32 Num, PMColor *NewColorPtr)
775-{
776- // Transmit the color to the control
777- CMRGBColor *ChgClrPtr = &NewColorPtr->color.rgb;
778- PickClrPtr->red = ChgClrPtr->red;
779- PickClrPtr->green = ChgClrPtr->green;
780- PickClrPtr->blue = ChgClrPtr->blue;
781-
782- Draw1Control(PickCtrl);
783-}
784-
785-
786-bool PickControlColor(ControlRef Ctrl,
787- RGBColor *ClrPtr,
788- ConstStr255Param Prompt
789- )
790-{
791- // Save old color so we can revert if necessary
792- RGBColor SavedColor = *ClrPtr;
793-
794- // Set up the globals:
795- PickCtrl = Ctrl;
796- PickClrPtr = ClrPtr;
797-
798- // For live updating
799- ColorChangedUPP ClrChg = NewColorChangedUPP(PickColorChangedFunc);
800-
801- // Fill in all those blanks...
802- ColorPickerInfo PickerData;
803- obj_clear(PickerData); // 0 is default for everything in it
804-
805- // Need to load the color and the prompt into the picker data
806- CMRGBColor *PkrClrPtr = &PickerData.theColor.color.rgb;
807- PkrClrPtr->red = ClrPtr->red;
808- PkrClrPtr->green = ClrPtr->green;
809- PkrClrPtr->blue = ClrPtr->blue;
810-
811- PickerData.placeWhere = kCenterOnMainScreen;
812- pstrcpy(PickerData.prompt, Prompt);
813-
814- PickerData.colorProc = ClrChg;
815-
816- // Go!
817- PickColor(&PickerData);
818-
819- bool IsOK = PickerData.newColorChosen;
820-
821- if (IsOK)
822- {
823- // Get the changed color
824- ClrPtr->red = PkrClrPtr->red;
825- ClrPtr->green = PkrClrPtr->green;
826- ClrPtr->blue = PkrClrPtr->blue;
827- }
828- else
829- {
830- // Revert to the saved color
831- *ClrPtr = SavedColor;
832- }
833- // Need to update
834- Draw1Control(Ctrl);
835-
836- DisposeColorChangedUPP(ClrChg);
837- return IsOK;
838-}
839-
840-
841-// Little more than a placeholder
842-static pascal ControlPartCode HitTester(ControlRef Ctrl, Point Loc)
843-{
844- return UserControlPart;
845-}
846-
847-
848-AutoHittability::AutoHittability()
849-{
850- HitTesterUPP = NewControlUserPaneHitTestUPP(HitTester);
851-}
852-
853-AutoHittability::~AutoHittability()
854-{
855- DisposeControlUserPaneHitTestUPP(HitTesterUPP);
856-}
857-
858-void AutoHittability::operator()(ControlRef Ctrl)
859-{
860- OSStatus err;
861-
862- err = SetControlData(
863- Ctrl, UserControlPart,
864- kControlUserPaneHitTestProcTag,
865- sizeof(HitTesterUPP), &HitTesterUPP
866- );
867- vassert(err == noErr, csprintf(temporary,"SetControlData error: %d",(int)err));
868-}
869-
870-
871-void BuildMenu(
872- ControlRef MenuCtrl,
873- bool (*BuildMenuItem)(int,uint8 *,bool &,void *),
874- void *BuildMenuData
875- )
876-{
877- // Extract the menu
878- MenuRef Menu = GetControlPopupMenuHandle(MenuCtrl);
879- assert(Menu);
880-
881- // Get rid of old contents
882- while(CountMenuItems(Menu)) DeleteMenuItem(Menu, 1);
883-
884- if(!BuildMenuItem) return;
885-
886- int Initial = 1;
887-
888- Str255 ItemName;
889- for(int indx=1; indx<=255; indx++)
890- {
891- bool ThisIsInitial = false;
892- if (!BuildMenuItem(indx,ItemName,ThisIsInitial,BuildMenuData)) break;
893- if (ThisIsInitial) Initial = indx;
894-
895- AppendMenu(Menu, "\pReplace Me");
896- SetMenuItemText(Menu, indx, ItemName);
897- }
898-
899- SetControl32BitMaximum(MenuCtrl,CountMenuItems(Menu));
900- SetControl32BitValue(MenuCtrl, Initial);
901-}
902-
903-
904-struct ModalDialogHandlerData
905-{
906- WindowRef DlgWindow;
907- bool IsSheet;
908- void (*DlgHandler)(ParsedControl &,void *);
909- void *DlgData;
910- bool IsOK; // Return whether OK was pressed
911-};
912-
913-static pascal OSStatus ModalDialogHandler(
914- EventHandlerCallRef HandlerCallRef,
915- EventRef Event,
916- void *Data
917- )
918-{
919- (void)(HandlerCallRef);
920-
921- OSStatus err;
922- ParsedControl Ctrl;
923-
924- err = GetEventParameter(Event,
925- kEventParamDirectObject,typeControlRef,
926- NULL, sizeof(ControlRef), NULL, &Ctrl.Ctrl);
927- vassert(err == noErr, csprintf(temporary,"GetEventParameter error: %d",(int)err));
928-
929- err = GetControlID(Ctrl.Ctrl,&Ctrl.ID);
930- vassert(err == noErr, csprintf(temporary,"GetControlID error: %d",(int)err));
931-
932- ModalDialogHandlerData *HDPtr = (ModalDialogHandlerData *)(Data);
933- if (HDPtr->DlgHandler)
934- HDPtr->DlgHandler(Ctrl,HDPtr->DlgData);
935-
936- // For quitting the dialog box
937- if (Ctrl.ID.signature == 0 && (Ctrl.ID.id == iOK || Ctrl.ID.id == iCANCEL))
938- {
939- // Which one pressed
940- HDPtr->IsOK = (Ctrl.ID.id == iOK);
941-
942- // Done with the window
943- StopModalDialog(HDPtr->DlgWindow,HDPtr->IsSheet);
944- }
945-
946- return noErr;
947-}
948-
949-
950-bool RunModalDialog(
951- WindowRef DlgWindow,
952- bool IsSheet,
953- void (*DlgHandler)(ParsedControl &,void *),
954- void *DlgData
955- )
956-{
957- OSStatus err;
958- ModalDialogHandlerData HandlerData;
959- HandlerData.DlgWindow = DlgWindow;
960- HandlerData.IsSheet = IsSheet;
961- HandlerData.DlgHandler = DlgHandler;
962- HandlerData.DlgData = DlgData;
963- HandlerData.IsOK = false;
964-
965- const int NumEventTypes = 1;
966- const EventTypeSpec EventTypes[NumEventTypes] =
967- {
968- {kEventClassControl, kEventControlHit}
969- };
970-
971- EventHandlerUPP HandlerUPP = NewEventHandlerUPP(ModalDialogHandler);
972- err = InstallWindowEventHandler(DlgWindow, HandlerUPP,
973- NumEventTypes, EventTypes,
974- &HandlerData, NULL);
975- vassert(err == noErr, csprintf(temporary,"InstallWindowEventHandler error: %d",(int)err));
976-
977- if (IsSheet)
978-#if USE_SHEETS
979- {
980- SetThemeWindowBackground(DlgWindow, kThemeBrushSheetBackgroundTransparent, false);
981- ShowSheetWindow(DlgWindow, ActiveNonFloatingWindow());
982- }
983-#else
984- ShowWindow(DlgWindow);
985-#endif
986- else
987- ShowWindow(DlgWindow);
988- RunAppModalLoopForWindow(DlgWindow);
989-
990- DisposeEventHandlerUPP(HandlerUPP);
991-
992- return HandlerData.IsOK;
993-}
994-
995-
996-void StopModalDialog(
997- WindowRef DlgWindow,
998- bool IsSheet
999- )
1000-{
1001- QuitAppModalLoopForWindow(DlgWindow);
1002- if (IsSheet)
1003-#if USE_SHEETS
1004- HideSheetWindow(DlgWindow);
1005-#else
1006- HideWindow(DlgWindow);
1007-#endif
1008- else
1009- HideWindow(DlgWindow);
1010-}
1011-
1012-
1013-Modal_Dialog::Modal_Dialog(WindowRef dialogWindow, bool isSheet)
1014- : m_dialogWindow (dialogWindow)
1015- , m_isSheet (isSheet)
1016- , m_result (false)
1017-{}
1018-
1019-bool Modal_Dialog::Run()
1020-{
1021-#if USE_SHEETS
1022- if (m_isSheet)
1023- {
1024- SetThemeWindowBackground(m_dialogWindow, kThemeBrushSheetBackgroundTransparent, false);
1025- ShowSheetWindow(m_dialogWindow, ActiveNonFloatingWindow());
1026- } else
1027-#endif
1028- ShowWindow(m_dialogWindow);
1029-
1030- RunAppModalLoopForWindow(m_dialogWindow);
1031- return m_result;
1032-}
1033-
1034-void Modal_Dialog::Stop(bool result)
1035-{
1036- QuitAppModalLoopForWindow(m_dialogWindow);
1037- m_result = result;
1038-
1039-#if USE_SHEETS
1040- if (m_isSheet)
1041- HideSheetWindow(m_dialogWindow);
1042- else
1043-#endif
1044- HideWindow(m_dialogWindow);
1045-}
1046-
1047-
1048-AutoTimer::AutoTimer(
1049- EventTimerInterval Delay,
1050- EventTimerInterval Interval,
1051- EventLoopTimerProcPtr Handler,
1052- void *HandlerData
1053- )
1054-{
1055- OSStatus err;
1056-
1057- EventLoopRef EventLoop = GetCurrentEventLoop();
1058- HandlerUPP = NewEventLoopTimerUPP(Handler);
1059- err = InstallEventLoopTimer(
1060- EventLoop,
1061- Delay, Interval,
1062- HandlerUPP, HandlerData,
1063- &Timer
1064- );
1065-
1066- vassert(err == noErr, csprintf(temporary, "Error in InstallEventLoopTimer: %d",(int)err));
1067-}
1068-
1069-AutoTimer::AutoTimer(
1070- EventTimerInterval Delay,
1071- EventTimerInterval Interval,
1072- TimerCallback Handler
1073- )
1074-{
1075- OSStatus err;
1076-
1077- EventLoopRef EventLoop = GetCurrentEventLoop();
1078- HandlerUPP = NewEventLoopTimerUPP(bounce_boosted_callback);
1079- err = InstallEventLoopTimer(
1080- EventLoop,
1081- Delay, Interval,
1082- HandlerUPP, this,
1083- &Timer
1084- );
1085-
1086- m_callback = Handler;
1087-
1088- vassert(err == noErr, csprintf(temporary, "Error in InstallEventLoopTimer: %d",(int)err));
1089-}
1090-
1091-AutoTimer::~AutoTimer()
1092-{
1093- RemoveEventLoopTimer(Timer);
1094- DisposeEventLoopTimerUPP(HandlerUPP);
1095-}
1096-
1097-
1098-AutoWatcher::AutoWatcher (ControlRef ctrl, int num_event_types, const EventTypeSpec* event_types)
1099-{
1100-
1101- m_EventHandlerUPP = NewEventHandlerUPP(callback);
1102- InstallControlEventHandler(ctrl, m_EventHandlerUPP,
1103- num_event_types, event_types,
1104- this, NULL);
1105-}
1106-
1107-pascal OSStatus AutoWatcher::callback (EventHandlerCallRef inCallRef,
1108- EventRef inEvent, void* inUserData)
1109-{
1110- // Hand off to the next event handler
1111- CallNextEventHandler(inCallRef, inEvent);
1112-
1113- // Do our thing
1114- return reinterpret_cast<AutoWatcher*>(inUserData)->act (inCallRef, inEvent);
1115-}
1116-
1117-const EventTypeSpec AutoControlWatcher::ControlWatcherEvents[1]
1118- = {{kEventClassControl, kEventControlHit}};
1119-
1120-const EventTypeSpec AutoKeystrokeWatcher::KeystrokeWatcherEvents[2]
1121- = {{kEventClassKeyboard, kEventRawKeyDown},{kEventClassKeyboard, kEventRawKeyRepeat}};
1122-
1123-OSStatus AutoKeystrokeWatcher::act (EventHandlerCallRef inCallRef, EventRef inEvent)
1124-{
1125- if (m_callback) {
1126- char character;
1127- GetEventParameter(inEvent, kEventParamKeyMacCharCodes, typeChar,
1128- NULL, sizeof(char), NULL, &character);
1129- m_callback (character);
1130- }
1131-
1132- return noErr;
1133-}
1134-
1135-AutoKeyboardWatcher::AutoKeyboardWatcher(
1136- EventHandlerProcPtr Handler // Called for every keystroke
1137- )
1138-{
1139- KeyboardHandlerUPP = NewEventHandlerUPP(Handler);
1140-}
1141-
1142-AutoKeyboardWatcher::~AutoKeyboardWatcher()
1143-{
1144- DisposeEventHandlerUPP(KeyboardHandlerUPP);
1145-}
1146-
1147-void AutoKeyboardWatcher::Watch(
1148- ControlRef Ctrl, // Control to watch keystrokes fat
1149- void *HandlerData
1150- )
1151-{
1152- OSStatus err;
1153-
1154- // From Br'fin's keyboard event handler
1155- const int NumKeyboardEvents = 3;
1156- const EventTypeSpec KeyboardEvents[NumKeyboardEvents] = {
1157- {kEventClassKeyboard, kEventRawKeyDown},
1158- {kEventClassKeyboard, kEventRawKeyModifiersChanged},
1159- {kEventClassKeyboard, kEventRawKeyRepeat}
1160- };
1161-
1162- err = InstallControlEventHandler(Ctrl, KeyboardHandlerUPP,
1163- NumKeyboardEvents, KeyboardEvents,
1164- HandlerData, NULL);
1165-
1166- vassert(err == noErr, csprintf(temporary, "Error in InstallControlEventHandler: %d",(int)err));
1167-}
1168-
1169-const EventTypeSpec AutoTabHandler::TabControlEvents[1]
1170- = {{kEventClassControl, kEventControlHit}};
1171-
1172-OSStatus AutoTabHandler::act (EventHandlerCallRef inCallRef, EventRef inEvent)
1173-{
1174- int new_value = GetControlValue(tab) - 1;
1175- if (new_value != old_value) {
1176- SetActiveTab (new_value);
1177- return (noErr);
1178- } else
1179- return (eventNotHandledErr);
1180-}
1181-
1182-void AutoTabHandler::SetActiveTab (int new_value)
1183-{
1184- old_value = new_value;
1185-
1186- for (int i = 0; i < panes.size (); ++i)
1187- if (i != new_value)
1188- SetControlVisibility (panes[i], false, true);
1189-
1190- ClearKeyboardFocus (window);
1191-
1192- SetControlVisibility (panes[new_value], true, true);
1193-
1194- Draw1Control (tab);
1195-}
1196-
1197-
1198-// Convert between control values and floats from 0 to 1.
1199-// Should be especially useful for sliders.
1200-
1201-float GetCtrlFloatValue(ControlRef Ctrl)
1202-{
1203- int32 MinVal = GetControl32BitMinimum(Ctrl);
1204- int32 MaxVal = GetControl32BitMaximum(Ctrl);
1205- assert(MaxVal != MinVal);
1206-
1207- int32 Value = GetControl32BitValue(Ctrl);
1208-
1209- return float(Value - MinVal) / float(MaxVal - MinVal);
1210-}
1211-
1212-void SetCtrlFloatValue(ControlRef Ctrl, float Value)
1213-{
1214- int32 MinVal = GetControl32BitMinimum(Ctrl);
1215- int32 MaxVal = GetControl32BitMaximum(Ctrl);
1216- assert(MaxVal != MinVal);
1217-
1218- // Round instead of truncating
1219- float FVal = MinVal + (MaxVal - MinVal)*Value;
1220- int IVal = FVal > 0 ? int(FVal + 0.5) : -int(-FVal + 0.5);
1221-
1222- SetControl32BitValue(Ctrl, IVal);
1223-}
1224-
1225-void initialize_MLTE()
1226-{
1227- TXNInitTextension (NULL, 0, 0);
1228-}
1229-
1230-
1231-
1232-// Similar to GetCtrlFromWindow, but doesn't mind if control doesn't exist
1233-static ControlRef get_control_from_window (DialogPTR dlg, int item)
1234-{
1235- OSStatus err;
1236-
1237- ControlID CtrlID;
1238- CtrlID.signature = global_signature;
1239- CtrlID.id = item;
1240-
1241- ControlRef control = NULL;
1242- err = GetControlByID(dlg,&CtrlID,&control);
1243-
1244- return control;
1245-}
1246-
1247-bool QQ_control_exists (DialogPTR dlg, int item)
1248-{
1249- return (get_control_from_window (dlg, item) != NULL);
1250-}
1251-
1252-void QQ_hide_control (DialogPTR dlg, int item)
1253-{
1254- HideControl (get_control_from_window (dlg, item));
1255-}
1256-
1257-void QQ_show_control (DialogPTR dlg, int item)
1258-{
1259- ShowControl (get_control_from_window (dlg, item));
1260-}
1261-
1262-bool QQ_get_boolean_control_value (DialogPTR dlg, int item)
1263-{
1264- return GetControl32BitValue (get_control_from_window (dlg, item));
1265-}
1266-
1267-void QQ_set_boolean_control_value (DialogPTR dlg, int item, bool value)
1268-{
1269- SetControl32BitValue (get_control_from_window (dlg, item), value ? 1 : 0);
1270-}
1271-
1272-int QQ_get_selector_control_value (DialogPTR dlg, int item)
1273-{
1274- return GetControl32BitValue (get_control_from_window (dlg, item)) - 1;
1275-}
1276-
1277-void QQ_set_selector_control_value (DialogPTR dlg, int item, int value)
1278-{
1279- SetControl32BitValue (get_control_from_window (dlg, item), value + 1);
1280-}
1281-
1282-void QQ_set_selector_control_labels (DialogPTR dlg, int item, const std::vector<std::string> labels)
1283-{
1284- // Possibly should extend to operate on radio groups too?
1285-
1286- // Get the menu
1287- ControlRef MenuCtrl = get_control_from_window (dlg, item);
1288- MenuRef Menu = GetControlPopupMenuHandle(MenuCtrl);
1289- if (!Menu)
1290- return;
1291-
1292- // Get rid of old contents
1293- while(CountMenuItems(Menu)) DeleteMenuItem(Menu, 1);
1294-
1295- // Add in new contents
1296- for (std::vector<std::string>::const_iterator it = labels.begin (); it != labels.end (); ++it) {
1297- CFStringRef cfstring = CFStringCreateWithCString(NULL, (*it).c_str (), kCFStringEncodingMacRoman);
1298- AppendMenuItemTextWithCFString(Menu, cfstring, 0, 0, NULL);
1299- CFRelease(cfstring);
1300- }
1301-
1302- SetControl32BitMaximum(MenuCtrl,CountMenuItems(Menu));
1303-}
1304-
1305-void QQ_set_selector_control_labels_from_stringset (DialogPTR dlg, int item, int stringset_id)
1306-{
1307- QQ_set_selector_control_labels (dlg, item, build_stringvector_from_stringset (stringset_id));
1308-}
1309-
1310-const std::string QQ_copy_string_from_text_control (DialogPTR dlg, int item)
1311-{
1312- ControlRef control = get_control_from_window (dlg, item);
1313-
1314- if (!control)
1315- return std::string();
1316-
1317- ControlKind kind;
1318- GetControlKind (control, &kind);
1319-
1320- ControlPartCode part;
1321- ResType tagName;
1322-
1323- if (kind.kind == kControlKindEditText)
1324- {
1325- part = kControlEditTextPart;
1326- tagName = kControlEditTextTextTag;
1327- }
1328- else if (kind.kind == kControlKindStaticText)
1329- {
1330- part = kControlLabelPart;
1331- tagName = kControlStaticTextTextTag;
1332- }
1333- else
1334- {
1335- return std::string();
1336- }
1337-
1338- Size size = 0;
1339- GetControlDataSize(control, part, tagName, &size);
1340-
1341- if (size == 0)
1342- return std::string();
1343-
1344- std::vector<char> buffer(size);
1345- GetControlData(control, part, tagName, buffer.size(), &buffer[0], NULL);
1346- return std::string(&buffer[0], buffer.size());
1347-}
1348-
1349-void QQ_copy_string_to_text_control (DialogPTR dlg, int item, const std::string &s)
1350-{
1351- ControlRef control = get_control_from_window (dlg, item);
1352-
1353- if (!control)
1354- return;
1355-
1356- ControlKind kind;
1357- GetControlKind (control, &kind);
1358-
1359- if (kind.kind == kControlKindEditText) {
1360- SetControlData(control, kControlEditTextPart, kControlEditTextTextTag, s.length (), s.c_str ());
1361- }
1362-
1363- if (kind.kind == kControlKindStaticText) {
1364- SetControlData(control, kControlLabelPart, kControlStaticTextTextTag, s.length (), s.c_str ());
1365- }
1366-
1367- Draw1Control (control);
1368-}
1369-
1370-extern void QQ_set_control_activity (DialogPTR dlg, int item, bool active)
1371-{
1372- if (active)
1373- ActivateControl (get_control_from_window (dlg, item));
1374- else
1375- DeactivateControl (get_control_from_window (dlg, item));
1376-}
1377-
1378-extern int32 QQ_extract_number_from_text_control (DialogPTR dlg, int item)
1379-{
1380- long result;
1381-
1382- copy_string_to_pstring(QQ_copy_string_from_text_control(dlg, item), ptemporary);
1383- StringToNum(ptemporary, &result);
1384- return result;
1385-}
1386-
1387-extern void QQ_insert_number_into_text_control (DialogPTR dlg, int item, int32 number)
1388-{
1389- NumToString(number, ptemporary);
1390- QQ_copy_string_to_text_control(dlg, item, pstring_to_string(ptemporary));
1391-}
1+/* csdialogs_macintosh.cpp
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+
21+ Sept-Nov 2001 (Woody Zenfell):
22+ renamed from csdialogs.cpp
23+ inserted get_dialog_control_value, from network_dialogs.cpp
24+ new functions copy_pstring_*_text_field()
25+
26+Jan 25, 2002 (Br'fin (Jeremy Parsons)):
27+ Added TARGET_API_MAC_CARBON for Carbon.h
28+ Added accessors for datafields now opaque in Carbon
29+
30+Feb 3, 2002 (Br'fin (Jeremy Parsons)):
31+ For carbon, replaced framing of our own group boxes with a theme seperator line at the top
32+
33+Feb 27, 2002 (Br'fin (Jeremy Parsons)):
34+ Adjusted modify_control to call the recommended De/ActivateControl
35+ for controls in a control hierarchy under Carbon
36+ Added utility routine GetListBoxListHandle for Carbon
37+*/
38+
39+#if defined(EXPLICIT_CARBON_HEADER)
40+ #include <Carbon/Carbon.h>
41+/*
42+#else
43+#include <Dialogs.h>
44+#include <TextUtils.h>
45+*/
46+#endif
47+
48+#include "cstypes.h"
49+#include "csdialogs.h"
50+#include "csmacros.h"
51+#include "csstrings.h"
52+#include "TextStrings.h"
53+
54+extern void update_any_window(
55+ WindowPtr window,
56+ EventRecord *event);
57+extern void activate_any_window(
58+ WindowPtr window,
59+ EventRecord *event,
60+ bool active);
61+
62+static bool cursor_tracking=true;
63+static dialog_header_proc_ptr header_proc;
64+static OSErr get_handle_for_dialog_item(DialogPtr, short, Handle *);
65+
66+DialogPtr myGetNewDialog(
67+ short id,
68+ void *storage,
69+ WindowPtr before,
70+ long refcon)
71+{
72+ DialogPtr dlg;
73+ short it;
74+ Handle ih;
75+ Rect ir;
76+
77+ dlg=GetNewDialog(id,storage,before);
78+ if (dlg) {
79+ SetWRefCon(GetDialogWindow(dlg),refcon);
80+ GetDialogItem(dlg,iOK,&it,&ih,&ir);
81+ if (it==kButtonDialogItem) {
82+ SetDialogDefaultItem(dlg,iOK);
83+ GetDialogItem(dlg,iCANCEL,&it,&ih,&ir);
84+ if (it==kButtonDialogItem)
85+ SetDialogCancelItem(dlg,iCANCEL);
86+ }
87+ }
88+ return dlg;
89+}
90+
91+static RGBColor third={0x5555,0x5555,0x5555};
92+
93+static void frame_useritems(
94+ DialogPtr dlg)
95+{
96+ RgnHandle outer,inner,good,bad;
97+ int i,n;
98+ short it;
99+ Handle ih;
100+ Rect ir;
101+ Boolean fillRegion = false;
102+
103+ good=NewRgn();
104+ bad=NewRgn();
105+ outer=NewRgn();
106+ inner=NewRgn();
107+ n=CountDITL(dlg);
108+ for (i=1; i<=n; i++) {
109+ GetDialogItem(dlg,i,&it,&ih,&ir);
110+ if ((it&~kItemDisableBit)==kUserDialogItem && !ih) {
111+#if defined(TARGET_API_MAC_CARBON)
112+ /*
113+ * A user item with no drawing proc installed is assumed to be a group box.
114+ * Use the appearance manager to draw a seperator line at the top of the group
115+ */
116+ // And keep it from being painted over
117+ RectRgn(outer,&ir);
118+ UnionRgn(bad,outer,bad);
119+
120+ ThemeDrawState curState =
121+ IsWindowActive(GetDialogWindow(dlg))?kThemeStateActive:kThemeStateInactive;
122+
123+ ir.bottom = ir.top + 2;
124+ ir.left += 10;
125+
126+ DrawThemeSeparator(&ir, curState);
127+#else
128+ /*
129+ * A user item with no drawing proc installed is assumed to be a group box.
130+ * Make a 1-pixel-thick frame from its rect and add it to the region to paint.
131+ */
132+ RectRgn(outer,&ir);
133+ CopyRgn(outer,inner);
134+ InsetRgn(inner,1,1);
135+ DiffRgn(outer,inner,outer);
136+ UnionRgn(good,outer,good);
137+#endif
138+ } else {
139+ /*
140+ * For all other items, add its rect to the region _not_ to paint.
141+ */
142+ RectRgn(outer,&ir);
143+ UnionRgn(bad,outer,bad);
144+ }
145+ }
146+ DisposeRgn(inner);
147+ DisposeRgn(outer);
148+ DiffRgn(good,bad,good);
149+ DisposeRgn(bad);
150+ if(fillRegion)
151+ {
152+ RGBForeColor(&third);
153+ PaintRgn(good);
154+ }
155+ ForeColor(blackColor);
156+ DisposeRgn(good);
157+}
158+
159+pascal Boolean general_filter_proc(
160+ DialogPtr dlg,
161+ EventRecord *event,
162+ short *hit)
163+{
164+ WindowPtr win;
165+ Rect frame;
166+ GrafPtr saveport;
167+
168+ GetPort(&saveport);
169+ SetDialogTracksCursor(dlg,cursor_tracking);
170+ switch (event->what) {
171+ case updateEvt:
172+ win=(WindowPtr)event->message;
173+ SetPort(GetWindowPort(win));
174+ if (GetWindowKind(win)==kDialogWindowKind) {
175+ if (header_proc) {
176+ GetPortBounds(GetWindowPort(GetDialogWindow(dlg)), &frame);
177+ (*header_proc)(GetDialogFromWindow(win),&frame);
178+ }
179+ frame_useritems(dlg);
180+ } else {
181+ update_any_window(win,event);
182+ }
183+ break;
184+ case activateEvt:
185+ win=(WindowPtr)event->message;
186+ if (GetWindowKind(win)!=kDialogWindowKind)
187+ activate_any_window(win,event,(event->modifiers&activeFlag)!=0);
188+ break;
189+ }
190+ SetPort(saveport);
191+ return StdFilterProc(dlg,event,hit);
192+}
193+
194+#if defined(TARGET_API_MAC_CARBON)
195+ModalFilterUPP general_filter_upp = NewModalFilterUPP(general_filter_proc);
196+#else
197+#if GENERATINGCFM
198+static RoutineDescriptor general_filter_desc =
199+ BUILD_ROUTINE_DESCRIPTOR(uppModalFilterProcInfo,general_filter_proc);
200+#define general_filter_upp (&general_filter_desc)
201+#else
202+#define general_filter_upp general_filter_proc
203+#endif
204+#endif
205+
206+ModalFilterUPP get_general_filter_upp(void)
207+{
208+ return general_filter_upp;
209+}
210+
211+void set_dialog_cursor_tracking(
212+ bool tracking)
213+{
214+ cursor_tracking=tracking;
215+}
216+
217+int32 extract_number_from_text_item(
218+ DialogPtr dlg,
219+ short item)
220+{
221+ Str255 str;
222+ int32 num;
223+ Handle ih;
224+
225+ get_handle_for_dialog_item(dlg, item, &ih);
226+ GetDialogItemText(ih,str);
227+ StringToNum(str,&num);
228+ return num;
229+}
230+
231+void insert_number_into_text_item(
232+ DialogPtr dlg,
233+ short item,
234+ int32 number)
235+{
236+ Str255 str;
237+ Handle ih;
238+
239+ NumToString(number,str);
240+ get_handle_for_dialog_item(dlg, item, &ih);
241+ SetDialogItemText(ih,str);
242+}
243+
244+bool hit_dialog_button(
245+ DialogPtr dlg,
246+ short item)
247+{
248+ short it;
249+ Handle ih;
250+ Rect ir;
251+ ControlHandle button;
252+ unsigned long ignore;
253+
254+ GetDialogItem(dlg,item,&it,&ih,&ir);
255+ if (it!=kButtonDialogItem)
256+ return false;
257+ button=(ControlHandle)ih;
258+ if (GetControlHilite(button)!=kControlNoPart)
259+ return false;
260+ HiliteControl(button,kControlButtonPart);
261+ Delay(8,&ignore);
262+ HiliteControl(button,kControlNoPart);
263+ return true;
264+}
265+
266+void modify_control(
267+ DialogPtr dlg,
268+ short item,
269+ short hilite,
270+ short value)
271+{
272+ short it;
273+ Handle ih;
274+ Rect ir;
275+ ControlHandle control;
276+
277+ GetDialogItem(dlg,item,&it,&ih,&ir);
278+ control=(ControlHandle)ih;
279+#if TARGET_API_MAC_CARBON
280+ if (hilite!=NONE)
281+ {
282+ // JTP: This works well for non-buttons, such as labels and edit text boxes
283+ // but is useless without a control hierarchy enabled, so we fall back to the old ways
284+ ControlRef hierarchyControl;
285+ if((hilite == CONTROL_INACTIVE || hilite == CONTROL_ACTIVE)
286+ && (GetDialogItemAsControl( dlg, item, &hierarchyControl ) == noErr))
287+ {
288+ if(hilite == CONTROL_INACTIVE)
289+ #ifdef __MACH__
290+ DisableControl(hierarchyControl);
291+ #else
292+ DeactivateControl(hierarchyControl);
293+ #endif
294+ else
295+ #ifdef __MACH__
296+ EnableControl(hierarchyControl);
297+ #else
298+ ActivateControl(hierarchyControl);
299+ #endif
300+ }
301+ else
302+ HiliteControl(control,hilite);
303+ }
304+#else
305+ if (hilite!=NONE)
306+ HiliteControl(control,hilite);
307+#endif
308+ if (value!=NONE)
309+ SetControlValue(control,value);
310+}
311+
312+void modify_radio_button_family(
313+ DialogPtr dlg,
314+ short firstItem,
315+ short lastItem,
316+ short activeItem)
317+{
318+ int item;
319+ short it;
320+ Handle ih;
321+ Rect ir;
322+ ControlHandle control;
323+ int value;
324+
325+ for (item=firstItem; item<=lastItem; item++) {
326+ GetDialogItem(dlg,item,&it,&ih,&ir);
327+ control=(ControlHandle)ih;
328+ if (item==activeItem) {
329+ value=kControlRadioButtonCheckedValue;
330+ } else {
331+ value=kControlRadioButtonUncheckedValue;
332+ }
333+ SetControlValue(control,value);
334+ }
335+}
336+
337+void set_dialog_header_proc(
338+ dialog_header_proc_ptr proc)
339+{
340+ header_proc=proc;
341+}
342+
343+void AdjustRect(
344+ Rect const *frame,
345+ Rect const *in,
346+ Rect *out,
347+ short how)
348+{
349+ int dim;
350+
351+ switch (how) {
352+ case centerRect:
353+ dim=in->right-in->left;
354+ out->left=(frame->left+frame->right-dim)/2;
355+ out->right=out->left+dim;
356+ dim=in->bottom-in->top;
357+ out->top=(frame->top+frame->bottom-dim)/2;
358+ out->bottom=out->top+dim;
359+ break;
360+ }
361+}
362+
363+void get_window_frame(
364+ WindowPtr win,
365+ Rect *frame)
366+{
367+ GrafPtr saveport;
368+ Rect pr;
369+
370+ GetPort(&saveport);
371+ SetPort(GetWindowPort(win));
372+ GetPortBounds(GetWindowPort(win), &pr);
373+ LocalToGlobal((Point *)&pr.top);
374+ LocalToGlobal((Point *)&pr.bottom);
375+ SetPort(saveport);
376+ *frame=pr;
377+}
378+
379+// ZZZ: added these to parallel SDL version. Now we have a common interface.
380+void
381+copy_pstring_from_text_field(DialogPtr dialog, short item, unsigned char* pstring) {
382+ Handle item_handle;
383+
384+ get_handle_for_dialog_item(dialog, item, &item_handle);
385+ GetDialogItemText(item_handle, pstring);
386+}
387+
388+void
389+copy_pstring_to_text_field(DialogPtr dialog, short item, const unsigned char* pstring) {
390+ Handle item_handle;
391+
392+ get_handle_for_dialog_item(dialog, item, &item_handle);
393+ SetDialogItemText(item_handle, pstring);
394+}
395+
396+void
397+copy_pstring_to_static_text(DialogPtr dialog, short item, const unsigned char* pstring) {
398+ Handle item_handle;
399+
400+ get_handle_for_dialog_item(dialog, item, &item_handle);
401+ SetDialogItemText(item_handle, pstring);
402+}
403+// ZZZ: moved here from network_dialogs_macintosh.cpp
404+short get_dialog_control_value(DialogPtr dialog, short which_control)
405+{
406+ Rect item_rect;
407+ short item_type;
408+ Handle item_handle;
409+
410+ GetDialogItem(dialog, which_control, &item_type, &item_handle, &item_rect);
411+ return GetControlValue((ControlHandle) item_handle);
412+}
413+
414+#ifndef mac
415+
416+// ZZZ: added these to inject a layer of indirection to slip in an SDL implementation and have the two versions share
417+void
418+copy_pstring_from_text_field(DialogPtr dialog, short item, unsigned char* pstring) {
419+ Rect item_rect;
420+ short item_type;
421+ Handle item_handle;
422+
423+ GetDialogItem(dialog, item, &item_type, &item_handle, &item_rect);
424+ GetDialogItemText(item_handle, pstring);
425+}
426+
427+void
428+copy_pstring_to_text_field(DialogPtr dialog, short item, const unsigned char* pstring) {
429+ Rect item_rect;
430+ short item_type;
431+ Handle item_handle;
432+
433+ GetDialogItem(dialog, item, &item_type, &item_handle, &item_rect);
434+ SetDialogItemText(item_handle, pstring);
435+}
436+
437+#endif
438+
439+static OSErr get_handle_for_dialog_item(DialogPtr __dialog, short __item, Handle *__handle)
440+{
441+ ControlRef control_ref;
442+ // If control embedding is turned on, then use appropriate variants
443+ if(GetDialogItemAsControl(__dialog, __item, &control_ref) == noErr)
444+ {
445+ *__handle= reinterpret_cast<Handle>(control_ref);
446+ } else {
447+ Rect item_rect;
448+ short item_type;
449+ Handle item_handle;
450+
451+ GetDialogItem(__dialog, __item, &item_type, &item_handle, &item_rect);
452+ *__handle= item_handle;
453+ }
454+ return noErr;
455+}
456+
457+#if TARGET_API_MAC_CARBON
458+// JTP: Taken from an AppearanceManager code sample
459+//ムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムム
460+// ・ GetListBoxListHandle
461+//ムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムムム
462+// Returns the list handle from a list box control.
463+//
464+pascal OSStatus
465+GetListBoxListHandle( ControlHandle control, ListHandle* list )
466+{
467+ Size actualSize;
468+ OSStatus err;
469+
470+ if ( control == nil )
471+ return paramErr;
472+
473+ if ( list == nil )
474+ return paramErr;
475+
476+ err = GetControlData( control, 0, kControlListBoxListHandleTag, sizeof( ListHandle ),
477+ (Ptr)list, &actualSize );
478+
479+ return err;
480+}
481+#endif
482+
483+
484+#include "csalerts.h"
485+#include <stdio.h>
486+#include <string.h>
487+#include "NibsUiHelpers.h"
488+
489+static OSType global_signature = 0;
490+
491+std::auto_ptr<SelfReleasingCFStringRef>
492+StringToCFString(const std::string& s)
493+{
494+ return std::auto_ptr<SelfReleasingCFStringRef>(
495+ new SelfReleasingCFStringRef(
496+ CFStringCreateWithCString(NULL, s.c_str(), kCFStringEncodingMacRoman)
497+ )
498+ );
499+}
500+
501+
502+
503+AutoNibWindow::AutoNibWindow(IBNibRef Nib, CFStringRef Name)
504+{
505+ OSStatus err;
506+
507+ err = CreateWindowFromNib(Nib,Name,&w);
508+
509+ const int BufferSize = 192; // Smaller than 256, the size of "temporary"
510+ char Buffer[BufferSize];
511+ if (err != noErr)
512+ {
513+ CFStringGetCString(Name, Buffer, BufferSize, kCFStringEncodingMacRoman);
514+ Buffer[BufferSize-1] = 0; // Null terminator byte
515+ }
516+ vassert(err == noErr,
517+ csprintf(temporary,"CreateWindowFromNib error: %d for window %s",(int)err,Buffer));
518+}
519+
520+
521+AutoNibWindow::~AutoNibWindow() {DisposeWindow(w);}
522+
523+
524+ControlRef GetCtrlFromWindow(WindowRef DlgWindow, uint32 Signature, uint32 ID)
525+{
526+ OSStatus err;
527+
528+ // Set up the popup menu
529+ ControlID CtrlID;
530+ CtrlID.signature = Signature;
531+ CtrlID.id = ID;
532+
533+ ControlRef Ctrl;
534+ err = GetControlByID(DlgWindow,&CtrlID,&Ctrl);
535+ vassert(err == noErr, csprintf(temporary,"GetControlByID error for sig and id: %d - %d %d",(int)err,(int)Signature,(int)ID));
536+ assert(Ctrl);
537+
538+ return Ctrl;
539+}
540+
541+
542+void SetControlActivity(ControlRef Ctrl, bool Activity)
543+{
544+
545+#ifdef __MACH__
546+ if(Activity)
547+ EnableControl(Ctrl);
548+ else
549+ DisableControl(Ctrl);
550+#else
551+ if(Activity)
552+ ActivateControl(Ctrl);
553+ else
554+ DeactivateControl(Ctrl);
555+#endif
556+}
557+
558+void GetStaticPascalText(ControlRef Ctrl, Str255 Text, int MaxLen)
559+{
560+ const int BufferLen = 255;
561+ char Buffer[BufferLen];
562+ Size ActualLen = 0;
563+
564+ GetControlData(Ctrl,
565+ kControlLabelPart,
566+ kControlStaticTextTextTag,
567+ BufferLen,
568+ Buffer,
569+ &ActualLen
570+ );
571+
572+ if (MaxLen < ActualLen) ActualLen = MaxLen;
573+ Text[0] = ActualLen;
574+ memcpy(Text+1,Buffer,ActualLen);
575+}
576+
577+void SetStaticPascalText(ControlRef Ctrl, ConstStr255Param Text)
578+{
579+ SetControlData(Ctrl,
580+ kControlLabelPart,
581+ kControlStaticTextTextTag,
582+ Text[0],
583+ Text+1
584+ );
585+}
586+
587+void GetStaticCText(ControlRef Ctrl, char *Text, int MaxLen)
588+{
589+ const int BufferLen = 255;
590+ char Buffer[BufferLen];
591+ Size ActualLen = 0;
592+
593+ GetControlData(Ctrl,
594+ kControlLabelPart,
595+ kControlStaticTextTextTag,
596+ BufferLen,
597+ Buffer,
598+ &ActualLen
599+ );
600+
601+ if (MaxLen < ActualLen) ActualLen = MaxLen;
602+ Text[ActualLen] = 0;
603+ memcpy(Text,Buffer,ActualLen);
604+}
605+
606+void SetStaticCText(ControlRef Ctrl, const char *Text)
607+{
608+ SetControlData(Ctrl,
609+ kControlLabelPart,
610+ kControlStaticTextTextTag,
611+ strlen(Text),
612+ Text
613+ );
614+}
615+
616+void GetEditPascalText(ControlRef Ctrl, Str255 Text, int MaxLen)
617+{
618+ const int BufferLen = 255;
619+ char Buffer[BufferLen];
620+ Size ActualLen = 0;
621+
622+ GetControlData(Ctrl,
623+ kControlEditTextPart,
624+ kControlEditTextTextTag,
625