annotate mac/dw.m @ 1821:69f9aa1e1b1e

Added bitmap button support to dw_window_set_bitmap() and added missing extention handling. Plus added a simple test of the code to dwtest.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 26 Oct 2012 04:46:13 +0000
parents d784b85b632e
children df7f3967c21e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2 * Dynamic Windows:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3 * A GTK like implementation of the MacOS GUI using Cocoa
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4 *
1559
bc3a11fe9a46 Don't use _dw_pool_drain() in dw_exit() on Mac... that drains and recreates the pool.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1558
diff changeset
5 * (C) 2011-2012 Brian Smith <brian@dbsoft.org>
721
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6 * (C) 2011 Mark Hessling <mark@rexx.org>
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7 *
1774
4cc999e757a3 Check for pointerArrayWithWeakObjects before weakObjectsPointerArray on Mac
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1773
diff changeset
8 * Requires 10.5 or later.
942
3c9dfb004df6 Minor change to the build comment.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 941
diff changeset
9 * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
11 #import <Cocoa/Cocoa.h>
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
12 #import <WebKit/WebKit.h>
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
13 #include "dw.h"
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
14 #include <sys/utsname.h>
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
15 #include <sys/socket.h>
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
16 #include <sys/un.h>
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
17 #include <sys/mman.h>
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
18 #include <sys/time.h>
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
19 #include <sys/stat.h>
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
20 #include <math.h>
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
21
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
22 /* Create a define to let us know to include Snow Leopard specific features */
1740
2d44ca344863 Test fix for warnings generated in Xcode 4.3... hopefully this still allows 10.5 builds to work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1719
diff changeset
23 #if defined(MAC_OS_X_VERSION_10_6) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED))
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
24 #define BUILDING_FOR_SNOW_LEOPARD
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
25 #endif
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
26
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
27 /* Macros to protect access to thread unsafe classes */
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
28 #define DW_MUTEX_LOCK { \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
29 if(DWThread != (DWTID)-1 && pthread_self() != DWThread && pthread_self() != _dw_mutex_locked) { \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
30 dw_mutex_lock(DWThreadMutex); \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
31 _dw_mutex_locked = pthread_self(); \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
32 dw_mutex_lock(DWThreadMutex2); \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
33 [DWObj performSelectorOnMainThread:@selector(synchronizeThread:) withObject:nil waitUntilDone:NO]; \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
34 dw_mutex_lock(DWRunMutex); \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
35 _locked_by_me = TRUE; } }
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
36 #define DW_MUTEX_UNLOCK { \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
37 if(pthread_self() != DWThread && _locked_by_me == TRUE) { \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
38 dw_mutex_unlock(DWRunMutex); \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
39 dw_mutex_unlock(DWThreadMutex2); \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
40 _dw_mutex_locked = (pthread_t)-1; \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
41 dw_mutex_unlock(DWThreadMutex); \
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
42 _locked_by_me = FALSE; } }
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
43
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
44 /* Macros to handle local auto-release pools */
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
45 #define DW_LOCAL_POOL_IN NSAutoreleasePool *localpool = nil; \
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
46 if(DWThread != (DWTID)-1 && pthread_self() != DWThread) \
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
47 localpool = [[NSAutoreleasePool alloc] init];
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
48 #define DW_LOCAL_POOL_OUT if(localpool) [localpool drain];
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
49
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
50 unsigned long _colors[] =
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
51 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
52 0x00000000, /* 0 black */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
53 0x000000bb, /* 1 red */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
54 0x0000bb00, /* 2 green */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
55 0x0000aaaa, /* 3 yellow */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
56 0x00cc0000, /* 4 blue */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
57 0x00bb00bb, /* 5 magenta */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
58 0x00bbbb00, /* 6 cyan */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
59 0x00bbbbbb, /* 7 white */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
60 0x00777777, /* 8 grey */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
61 0x000000ff, /* 9 bright red */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
62 0x0000ff00, /* 10 bright green */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
63 0x0000eeee, /* 11 bright yellow */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
64 0x00ff0000, /* 12 bright blue */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
65 0x00ff00ff, /* 13 bright magenta */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
66 0x00eeee00, /* 14 bright cyan */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
67 0x00ffffff, /* 15 bright white */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
68 0xff000000 /* 16 default color */
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
69 };
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
70
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
71 /*
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
72 * List those icons that have transparency first
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
73 */
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
74 #define NUM_EXTS 8
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
75 char *image_exts[NUM_EXTS] =
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
76 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
77 ".png",
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
78 ".ico",
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
79 ".icns",
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
80 ".gif",
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
81 ".jpg",
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
82 ".jpeg",
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
83 ".tiff",
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
84 ".bmp"
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
85 };
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
86
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
87 char *_dw_get_image_extension( char *filename )
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
88 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
89 char *file = alloca(strlen(filename) + 6);
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
90 int found_ext = 0,i;
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
91
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
92 /* Try various extentions */
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
93 for ( i = 0; i < NUM_EXTS; i++ )
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
94 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
95 strcpy( file, filename );
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
96 strcat( file, image_exts[i] );
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
97 if ( access( file, R_OK ) == 0 )
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
98 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
99 found_ext = 1;
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
100 break;
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
101 }
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
102 }
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
103 if ( found_ext == 1 )
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
104 {
940
b5ae9cf15f68 Fix for returning wrong extension in _dw_get_image_extension; only worked for .ico files
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 939
diff changeset
105 return image_exts[i];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
106 }
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
107 return NULL;
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
108 }
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
109
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
110 unsigned long _get_color(unsigned long thiscolor)
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
111 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
112 if(thiscolor & DW_RGB_COLOR)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
113 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
114 return thiscolor & ~DW_RGB_COLOR;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
115 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
116 else if(thiscolor < 17)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
117 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
118 return _colors[thiscolor];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
119 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
120 return 0;
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
121 }
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
122
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
123 /* Thread specific storage */
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
124 #if !defined(GARBAGE_COLLECT)
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
125 pthread_key_t _dw_pool_key;
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
126 #endif
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
127 pthread_key_t _dw_fg_color_key;
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
128 pthread_key_t _dw_bg_color_key;
1770
2396655d43f1 Fix some warnings with Mac 10.8 and Xcode 4.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1769
diff changeset
129 int DWOSMajor, DWOSMinor, DWOSBuild;
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
130 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
131
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
132 /* Create a default colors for a thread */
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
133 void _init_colors(void)
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
134 {
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
135 NSColor *fgcolor = [[NSColor grayColor] retain];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
136
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
137 pthread_setspecific(_dw_fg_color_key, fgcolor);
891
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
138 pthread_setspecific(_dw_bg_color_key, NULL);
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
139 }
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
140
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
141 typedef struct _sighandler
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
142 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
143 struct _sighandler *next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
144 ULONG message;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
145 HWND window;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
146 int id;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
147 void *signalfunction;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
148 void *data;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
149
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
150 } SignalHandler;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
151
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
152 SignalHandler *Root = NULL;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
153
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
154 /* Some internal prototypes */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
155 static void _do_resize(Box *thisbox, int x, int y);
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
156 void _handle_resize_events(Box *thisbox);
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
157 int _remove_userdata(UserData **root, char *varname, int all);
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
158 int _dw_main_iteration(NSDate *date);
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
159
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
160 /* Internal function to queue a window redraw */
1422
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
161 void _dw_redraw(id window, int skip)
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
162 {
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
163 static id lastwindow = nil;
1425
1628bf383893 Changes to _dw_redraw() to prevent infinite recursion on OS/2, Win and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1422
diff changeset
164 id redraw = lastwindow;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
165
1422
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
166 if(skip && window == nil)
1425
1628bf383893 Changes to _dw_redraw() to prevent infinite recursion on OS/2, Win and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1422
diff changeset
167 return;
1628bf383893 Changes to _dw_redraw() to prevent infinite recursion on OS/2, Win and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1422
diff changeset
168
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
169 lastwindow = window;
1425
1628bf383893 Changes to _dw_redraw() to prevent infinite recursion on OS/2, Win and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1422
diff changeset
170 if(redraw != lastwindow && redraw != nil)
1628bf383893 Changes to _dw_redraw() to prevent infinite recursion on OS/2, Win and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1422
diff changeset
171 {
1628bf383893 Changes to _dw_redraw() to prevent infinite recursion on OS/2, Win and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1422
diff changeset
172 dw_window_redraw(redraw);
1628bf383893 Changes to _dw_redraw() to prevent infinite recursion on OS/2, Win and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1422
diff changeset
173 }
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
174 }
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
175
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
176 SignalHandler *_get_handler(HWND window, int messageid)
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
177 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
178 SignalHandler *tmp = Root;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
179
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
180 /* Find any callbacks for this function */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
181 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
182 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
183 if(tmp->message == messageid && window == tmp->window)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
184 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
185 return tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
186 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
187 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
188 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
189 return NULL;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
190 }
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
191
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
192 typedef struct
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
193 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
194 ULONG message;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
195 char name[30];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
196
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
197 } SignalList;
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
198
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
199 /* List of signals */
803
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
200 #define SIGNALMAX 17
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
201
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
202 SignalList SignalTranslate[SIGNALMAX] = {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
203 { 1, DW_SIGNAL_CONFIGURE },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
204 { 2, DW_SIGNAL_KEY_PRESS },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
205 { 3, DW_SIGNAL_BUTTON_PRESS },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
206 { 4, DW_SIGNAL_BUTTON_RELEASE },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
207 { 5, DW_SIGNAL_MOTION_NOTIFY },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
208 { 6, DW_SIGNAL_DELETE },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
209 { 7, DW_SIGNAL_EXPOSE },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
210 { 8, DW_SIGNAL_CLICKED },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
211 { 9, DW_SIGNAL_ITEM_ENTER },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
212 { 10, DW_SIGNAL_ITEM_CONTEXT },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
213 { 11, DW_SIGNAL_LIST_SELECT },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
214 { 12, DW_SIGNAL_ITEM_SELECT },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
215 { 13, DW_SIGNAL_SET_FOCUS },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
216 { 14, DW_SIGNAL_VALUE_CHANGED },
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
217 { 15, DW_SIGNAL_SWITCH_PAGE },
803
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
218 { 16, DW_SIGNAL_TREE_EXPAND },
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
219 { 17, DW_SIGNAL_COLUMN_CLICK }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
220 };
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
221
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
222 int _event_handler1(id object, NSEvent *event, int message)
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
223 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
224 SignalHandler *handler = _get_handler(object, message);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
225 /* NSLog(@"Event handler - type %d\n", message); */
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
226
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
227 if(handler)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
228 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
229 switch(message)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
230 {
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
231 /* Timer event */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
232 case 0:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
233 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
234 int (* API timerfunc)(void *) = (int (* API)(void *))handler->signalfunction;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
235
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
236 if(!timerfunc(handler->data))
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
237 dw_timer_disconnect(handler->id);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
238 return 0;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
239 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
240 /* Configure/Resize event */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
241 case 1:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
242 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
243 int (*sizefunc)(HWND, int, int, void *) = handler->signalfunction;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
244 NSSize size;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
245
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
246 if([object isKindOfClass:[NSWindow class]])
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
247 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
248 NSWindow *window = object;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
249 size = [[window contentView] frame].size;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
250 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
251 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
252 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
253 NSView *view = object;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
254 size = [view frame].size;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
255 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
256
706
79b38b1f3346 Scrollbar event fixes... scale was wrong... not sure it is correct but it is better.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 705
diff changeset
257 if(size.width > 0 && size.height > 0)
79b38b1f3346 Scrollbar event fixes... scale was wrong... not sure it is correct but it is better.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 705
diff changeset
258 {
79b38b1f3346 Scrollbar event fixes... scale was wrong... not sure it is correct but it is better.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 705
diff changeset
259 return sizefunc(object, size.width, size.height, handler->data);
79b38b1f3346 Scrollbar event fixes... scale was wrong... not sure it is correct but it is better.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 705
diff changeset
260 }
79b38b1f3346 Scrollbar event fixes... scale was wrong... not sure it is correct but it is better.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 705
diff changeset
261 return 0;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
262 }
723
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
263 case 2:
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
264 {
1748
e4fcd1e81f0d Added optional utf8 parameter to keypress callback on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1744
diff changeset
265 int (*keypressfunc)(HWND, char, int, int, void *, char *) = handler->signalfunction;
723
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
266 NSString *nchar = [event charactersIgnoringModifiers];
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
267 int special = (int)[event modifierFlags];
724
41080d22edc8 Couple more fixes to keyhandling... committed before I finished what I was doing...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 723
diff changeset
268 unichar vk = [nchar characterAtIndex:0];
1748
e4fcd1e81f0d Added optional utf8 parameter to keypress callback on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1744
diff changeset
269 char *utf8 = NULL, ch = '\0';
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
270
723
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
271 /* Handle a valid key */
724
41080d22edc8 Couple more fixes to keyhandling... committed before I finished what I was doing...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 723
diff changeset
272 if([nchar length] == 1)
723
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
273 {
1748
e4fcd1e81f0d Added optional utf8 parameter to keypress callback on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1744
diff changeset
274 char *tmp = (char *)[nchar UTF8String];
899
3fbba8b1f440 Don't pass in a partial UTF8 string in the character field during key press events.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 898
diff changeset
275 if(tmp && strlen(tmp) == 1)
723
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
276 {
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
277 ch = tmp[0];
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
278 }
1748
e4fcd1e81f0d Added optional utf8 parameter to keypress callback on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1744
diff changeset
279 utf8 = tmp;
723
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
280 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
281
1748
e4fcd1e81f0d Added optional utf8 parameter to keypress callback on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1744
diff changeset
282 return keypressfunc(handler->window, ch, (int)vk, special, handler->data, utf8);
723
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
283 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
284 /* Button press and release event */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
285 case 3:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
286 case 4:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
287 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
288 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
289 NSPoint p = [NSEvent mouseLocation];
922
07f9a73c6847 Fix for button press/release events coordinates being relative to the window instead of the screen on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 921
diff changeset
290 int button = 1;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
291
1222
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
292 if([event isMemberOfClass:[NSEvent class]])
922
07f9a73c6847 Fix for button press/release events coordinates being relative to the window instead of the screen on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 921
diff changeset
293 {
1222
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
294 id view = [[[event window] contentView] superview];
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
295 NSEventType type = [event type];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
296
1222
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
297 p = [view convertPoint:[event locationInWindow] toView:object];
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
298
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
299 if(type == NSRightMouseDown || type == NSRightMouseUp)
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
300 {
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
301 button = 2;
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
302 }
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
303 else if(type == NSOtherMouseDown || type == NSOtherMouseUp)
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
304 {
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
305 button = 3;
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
306 }
1647
b2c26ed9031c On Mac set button to 2 (right) when Control key is pressed and left clicking
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1644
diff changeset
307 else if([event modifierFlags] & NSControlKeyMask)
b2c26ed9031c On Mac set button to 2 (right) when Control key is pressed and left clicking
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1644
diff changeset
308 {
b2c26ed9031c On Mac set button to 2 (right) when Control key is pressed and left clicking
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1644
diff changeset
309 button = 2;
b2c26ed9031c On Mac set button to 2 (right) when Control key is pressed and left clicking
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1644
diff changeset
310 }
922
07f9a73c6847 Fix for button press/release events coordinates being relative to the window instead of the screen on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 921
diff changeset
311 }
07f9a73c6847 Fix for button press/release events coordinates being relative to the window instead of the screen on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 921
diff changeset
312
954
cfb12bf3bb06 Fixes for some more coordinate system issues on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 953
diff changeset
313 return buttonfunc(object, (int)p.x, (int)p.y, button, handler->data);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
314 }
886
d94a4fa0359e Implemented the motion notify event on Mac. Most of it was there except the event handler.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 882
diff changeset
315 /* Motion notify event */
d94a4fa0359e Implemented the motion notify event on Mac. Most of it was there except the event handler.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 882
diff changeset
316 case 5:
d94a4fa0359e Implemented the motion notify event on Mac. Most of it was there except the event handler.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 882
diff changeset
317 {
d94a4fa0359e Implemented the motion notify event on Mac. Most of it was there except the event handler.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 882
diff changeset
318 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
945
254b50be1bc1 Coordinate system changes to button press and motion notify events on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 944
diff changeset
319 id view = [[[event window] contentView] superview];
254b50be1bc1 Coordinate system changes to button press and motion notify events on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 944
diff changeset
320 NSPoint p = [view convertPoint:[event locationInWindow] toView:object];
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
321 SEL spmb = NSSelectorFromString(@"pressedMouseButtons");
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
322 IMP ipmb = [[NSEvent class] respondsToSelector:spmb] ? [[NSEvent class] methodForSelector:spmb] : 0;
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
323 int buttonmask = ipmb ? (int)ipmb([NSEvent class], spmb) : (1 << [event buttonNumber]);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
324
954
cfb12bf3bb06 Fixes for some more coordinate system issues on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 953
diff changeset
325 return motionfunc(object, (int)p.x, (int)p.y, buttonmask, handler->data);
886
d94a4fa0359e Implemented the motion notify event on Mac. Most of it was there except the event handler.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 882
diff changeset
326 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
327 /* Window close event */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
328 case 6:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
329 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
330 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
331 return closefunc(object, handler->data);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
332 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
333 /* Window expose/draw event */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
334 case 7:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
335 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
336 DWExpose exp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
337 int (* API exposefunc)(HWND, DWExpose *, void *) = (int (* API)(HWND, DWExpose *, void *))handler->signalfunction;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
338 NSRect rect = [object frame];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
339
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
340 exp.x = rect.origin.x;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
341 exp.y = rect.origin.y;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
342 exp.width = rect.size.width;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
343 exp.height = rect.size.height;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
344 int result = exposefunc(object, &exp, handler->data);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
345 [[object window] flushWindow];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
346 return result;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
347 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
348 /* Clicked event for buttons and menu items */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
349 case 8:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
350 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
351 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
352
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
353 return clickfunc(object, handler->data);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
354 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
355 /* Container class selection event */
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
356 case 9:
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
357 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
358 int (*containerselectfunc)(HWND, char *, void *) = handler->signalfunction;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
359
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
360 return containerselectfunc(handler->window, (char *)event, handler->data);
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
361 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
362 /* Container context menu event */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
363 case 10:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
364 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
365 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
366 char *text = (char *)event;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
367 void *user = NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
368 LONG x,y;
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
369
1061
d91e09dc3865 Fix for the item data field of the context event always being NULL even for tree items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1051
diff changeset
370 /* Fill in both items for the tree */
d91e09dc3865 Fix for the item data field of the context event always being NULL even for tree items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1051
diff changeset
371 if([object isKindOfClass:[NSOutlineView class]])
d91e09dc3865 Fix for the item data field of the context event always being NULL even for tree items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1051
diff changeset
372 {
d91e09dc3865 Fix for the item data field of the context event always being NULL even for tree items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1051
diff changeset
373 id item = event;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
374 NSString *nstr = [item objectAtIndex:1];
1061
d91e09dc3865 Fix for the item data field of the context event always being NULL even for tree items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1051
diff changeset
375 text = (char *)[nstr UTF8String];
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
376 NSValue *value = [item objectAtIndex:2];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
377 if(value && [value isKindOfClass:[NSValue class]])
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
378 {
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
379 user = [value pointerValue];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
380 }
1061
d91e09dc3865 Fix for the item data field of the context event always being NULL even for tree items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1051
diff changeset
381 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
382
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
383 dw_pointer_query_pos(&x, &y);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
384
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
385 return containercontextfunc(handler->window, text, (int)x, (int)y, handler->data, user);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
386 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
387 /* Generic selection changed event for several classes */
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
388 case 11:
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
389 case 14:
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
390 {
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
391 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction;
1102
cfe7d2b6bc16 Added DW_INT_TO_POINTER/DW_UINT_TO_POINTER/DW_POINTER_TO_INT/DW_POINTER_TO_UINT macros.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1101
diff changeset
392 int selected = DW_POINTER_TO_INT(event);
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
393
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
394 return valuechangedfunc(handler->window, selected, handler->data);;
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
395 }
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
396 /* Tree class selection event */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
397 case 12:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
398 {
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
399 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction;
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
400 char *text = (char *)event;
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
401 void *user = NULL;
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
402 id item = nil;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
403
710
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
404 if([object isKindOfClass:[NSOutlineView class]])
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
405 {
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
406 item = (id)event;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
407 NSString *nstr = [item objectAtIndex:1];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
408
727
f190b5c2ce16 Fixed 2 errors in the tree select event handler. Also removed unused experimental code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 726
diff changeset
409 if(nstr)
712
01107d8e033e Fixed the scrollbar maximum range to be correct. Also added some MLE code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 711
diff changeset
410 {
01107d8e033e Fixed the scrollbar maximum range to be correct. Also added some MLE code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 711
diff changeset
411 text = strdup([nstr UTF8String]);
01107d8e033e Fixed the scrollbar maximum range to be correct. Also added some MLE code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 711
diff changeset
412 }
713
2c8fc0fd8c11 Don't send tree events with no selected item. Also don't strdup a NULL string.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 712
diff changeset
413 else
2c8fc0fd8c11 Don't send tree events with no selected item. Also don't strdup a NULL string.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 712
diff changeset
414 {
2c8fc0fd8c11 Don't send tree events with no selected item. Also don't strdup a NULL string.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 712
diff changeset
415 text = NULL;
2c8fc0fd8c11 Don't send tree events with no selected item. Also don't strdup a NULL string.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 712
diff changeset
416 }
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
417
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
418 NSValue *value = [item objectAtIndex:2];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
419 if(value && [value isKindOfClass:[NSValue class]])
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
420 {
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
421 user = [value pointerValue];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
422 }
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
423 int result = treeselectfunc(handler->window, item, text, handler->data, user);
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
424 if(text)
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
425 {
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
426 free(text);
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
427 }
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
428 return result;
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
429 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
430
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
431 return treeselectfunc(handler->window, item, text, handler->data, user);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
432 }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
433 /* Set Focus event */
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
434 case 13:
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
435 {
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
436 int (* API setfocusfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
437
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
438 return setfocusfunc(handler->window, handler->data);
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
439 }
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
440 /* Notebook page change event */
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
441 case 15:
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
442 {
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
443 int (* API switchpagefunc)(HWND, unsigned long, void *) = (int (* API)(HWND, unsigned long, void *))handler->signalfunction;
1102
cfe7d2b6bc16 Added DW_INT_TO_POINTER/DW_UINT_TO_POINTER/DW_POINTER_TO_INT/DW_POINTER_TO_UINT macros.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1101
diff changeset
444 int pageid = DW_POINTER_TO_INT(event);
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
445
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
446 return switchpagefunc(handler->window, pageid, handler->data);
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
447 }
722
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
448 case 16:
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
449 {
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
450 int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))handler->signalfunction;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
451
722
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
452 return treeexpandfunc(handler->window, (HTREEITEM)event, handler->data);
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
453 }
803
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
454 case 17:
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
455 {
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
456 int (*clickcolumnfunc)(HWND, int, void *) = handler->signalfunction;
1102
cfe7d2b6bc16 Added DW_INT_TO_POINTER/DW_UINT_TO_POINTER/DW_POINTER_TO_INT/DW_POINTER_TO_UINT macros.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1101
diff changeset
457 int column_num = DW_POINTER_TO_INT(event);
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
458
803
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
459 return clickcolumnfunc(handler->window, column_num, handler->data);
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
460 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
461 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
462 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
463 return -1;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
464 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
465
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
466 /* Sub function to handle redraws */
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
467 int _event_handler(id object, NSEvent *event, int message)
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
468 {
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
469 int ret = _event_handler1(object, event, message);
1422
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
470 if(ret != -1)
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
471 _dw_redraw(nil, FALSE);
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
472 return ret;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
473 }
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
474
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
475 /* Subclass for the Timer type */
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
476 @interface DWTimerHandler : NSObject { }
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
477 -(void)runTimer:(id)sender;
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
478 @end
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
479
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
480 @implementation DWTimerHandler
674
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
481 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); }
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
482 @end
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
483
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
484 NSApplication *DWApp;
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
485 NSMenu *DWMainMenu;
740
bb3b2d804f0e Working on fonts some more.... setting a default label font that is smaller.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 739
diff changeset
486 NSFont *DWDefaultFont;
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
487 DWTimerHandler *DWHandler;
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
488 #if !defined(GARBAGE_COLLECT)
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
489 NSAutoreleasePool *pool;
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
490 #endif
661
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
491 HWND _DWLastDrawable;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
492 HMTX DWRunMutex;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
493 HMTX DWThreadMutex;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
494 HMTX DWThreadMutex2;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
495 DWTID DWThread = (DWTID)-1;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
496 DWTID _dw_mutex_locked = (DWTID)-1;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
497
1558
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
498 /* Send fake event to make sure the loop isn't stuck */
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
499 void _dw_wakeup_app()
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
500 {
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
501 [DWApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
502 location:NSMakePoint(0, 0)
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
503 modifierFlags:0
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
504 timestamp:0
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
505 windowNumber:0
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
506 context:NULL
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
507 subtype:0
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
508 data1:0
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
509 data2:0]
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
510 atStart:NO];
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
511 }
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
512
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
513 /* Used for doing bitblts from the main thread */
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
514 typedef struct _bitbltinfo
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
515 {
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
516 id src;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
517 id dest;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
518 int xdest;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
519 int ydest;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
520 int width;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
521 int height;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
522 int xsrc;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
523 int ysrc;
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
524 int srcwidth;
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
525 int srcheight;
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
526 } DWBitBlt;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
527
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
528 /* Subclass for a test object type */
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
529 @interface DWObject : NSObject {}
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
530 -(void)uselessThread:(id)sender;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
531 -(void)synchronizeThread:(id)param;
1378
a54720b10821 Fix menu items getting stuck highlighted on Mac if the action triggered a window focus change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1376
diff changeset
532 -(void)menuHandler:(id)param;
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
533 -(void)doBitBlt:(id)param;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
534 -(void)doFlush:(id)param;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
535 @end
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
536
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
537 @interface DWMenuItem : NSMenuItem
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
538 {
1517
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
539 int check;
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
540 }
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
541 -(void)setCheck:(int)input;
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
542 -(int)check;
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
543 -(void)dealloc;
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
544 @end
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
545
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
546 @implementation DWObject
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
547 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
548 -(void)synchronizeThread:(id)param
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
549 {
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
550 pthread_mutex_unlock(DWRunMutex);
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
551 pthread_mutex_lock(DWThreadMutex2);
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
552 pthread_mutex_unlock(DWThreadMutex2);
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
553 pthread_mutex_lock(DWRunMutex);
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
554 }
1378
a54720b10821 Fix menu items getting stuck highlighted on Mac if the action triggered a window focus change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1376
diff changeset
555 -(void)menuHandler:(id)param
a54720b10821 Fix menu items getting stuck highlighted on Mac if the action triggered a window focus change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1376
diff changeset
556 {
1517
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
557 DWMenuItem *item = param;
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
558 if([item check])
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
559 {
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
560 if([item state] == NSOnState)
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
561 [item setState:NSOffState];
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
562 else
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
563 [item setState:NSOnState];
1517
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
564 }
1378
a54720b10821 Fix menu items getting stuck highlighted on Mac if the action triggered a window focus change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1376
diff changeset
565 _event_handler(param, nil, 8);
a54720b10821 Fix menu items getting stuck highlighted on Mac if the action triggered a window focus change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1376
diff changeset
566 }
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
567 -(void)doBitBlt:(id)param
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
568 {
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
569 NSValue *bi = (NSValue *)param;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
570 DWBitBlt *bltinfo = (DWBitBlt *)[bi pointerValue];
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
571 id bltdest = bltinfo->dest;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
572 id bltsrc = bltinfo->src;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
573
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
574 if([bltdest isMemberOfClass:[NSBitmapImageRep class]])
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
575 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
576 [NSGraphicsContext saveGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
577 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
578 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:bltdest] graphicsPort] flipped:YES]];
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
579 [[[NSDictionary alloc] initWithObjectsAndKeys:bltdest, NSGraphicsContextDestinationAttributeName, nil] autorelease];
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
580 }
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
581 else
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
582 {
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
583 if([bltdest lockFocusIfCanDraw] == NO)
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
584 {
917
8567c9ac089d Switched back to using the dealloc() method in dw_pixmap_destroy() to stop a memory leak on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 916
diff changeset
585 free(bltinfo);
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
586 return;
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
587 }
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
588 _DWLastDrawable = bltinfo->dest;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
589 }
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
590 if([bltsrc isMemberOfClass:[NSBitmapImageRep class]])
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
591 {
910
329f2ca62f1b Switched to using a different potentially slower NSImage conversion to support Leopard.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 909
diff changeset
592 NSBitmapImageRep *rep = bltsrc;
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
593 NSImage *image = [NSImage alloc];
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
594 SEL siwc = NSSelectorFromString(@"initWithCGImage");
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
595
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
596 if([image respondsToSelector:siwc])
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
597 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
598 IMP iiwc = [image methodForSelector:siwc];
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
599 image = iiwc(image, siwc, [rep CGImage], NSZeroSize);
910
329f2ca62f1b Switched to using a different potentially slower NSImage conversion to support Leopard.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 909
diff changeset
600 }
329f2ca62f1b Switched to using a different potentially slower NSImage conversion to support Leopard.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 909
diff changeset
601 else
329f2ca62f1b Switched to using a different potentially slower NSImage conversion to support Leopard.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 909
diff changeset
602 {
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
603 image = [image initWithSize:[rep size]];
910
329f2ca62f1b Switched to using a different potentially slower NSImage conversion to support Leopard.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 909
diff changeset
604 [image addRepresentation:rep];
329f2ca62f1b Switched to using a different potentially slower NSImage conversion to support Leopard.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 909
diff changeset
605 }
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
606 if(bltinfo->srcwidth != -1)
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
607 {
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
608 [image drawInRect:NSMakeRect(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height)
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
609 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->srcwidth, bltinfo->srcheight)
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
610 operation:NSCompositeSourceOver fraction:1.0];
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
611 }
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
612 else
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
613 {
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
614 [image drawAtPoint:NSMakePoint(bltinfo->xdest, bltinfo->ydest)
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
615 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height)
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
616 operation:NSCompositeSourceOver fraction:1.0];
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
617 }
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
618 [bltsrc release];
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
619 [image release];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
620 }
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
621 if([bltdest isMemberOfClass:[NSBitmapImageRep class]])
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
622 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
623 [NSGraphicsContext restoreGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
624 }
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
625 else
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
626 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
627 [bltdest unlockFocus];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
628 }
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
629 free(bltinfo);
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
630 }
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
631 -(void)doFlush:(id)param
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
632 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
633 if(_DWLastDrawable)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
634 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
635 id object = _DWLastDrawable;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
636 NSWindow *window = [object window];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
637 [window flushWindow];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
638 }
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
639 }
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
640 -(void)doWindowFunc:(id)param
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
641 {
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
642 NSValue *v = (NSValue *)param;
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
643 void **params = (void **)[v pointerValue];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
644 void (* windowfunc)(void *);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
645
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
646 if(params)
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
647 {
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
648 windowfunc = params[0];
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
649 if(windowfunc)
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
650 {
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
651 windowfunc(params[1]);
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
652 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
653 }
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
654 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
655 @end
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
656
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
657 DWObject *DWObj;
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
658
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
659 /* So basically to implement our event handlers...
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
660 * it looks like we are going to have to subclass
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
661 * basically everything. Was hoping to add methods
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
662 * to the superclasses but it looks like you can
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
663 * only add methods and no variables, which isn't
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
664 * going to work. -Brian
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
665 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
666
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
667 /* Subclass for a box type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
668 @interface DWBox : NSView
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
669 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
670 Box *box;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
671 void *userdata;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
672 NSColor *bgcolor;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
673 }
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
674 -(id)init;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
675 -(void)dealloc;
666
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
676 -(Box *)box;
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
677 -(id)contentView;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
678 -(void *)userdata;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
679 -(void)setUserdata:(void *)input;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
680 -(void)drawRect:(NSRect)rect;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
681 -(BOOL)isFlipped;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
682 -(void)mouseDown:(NSEvent *)theEvent;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
683 -(void)mouseUp:(NSEvent *)theEvent;
701
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
684 -(NSMenu *)menuForEvent:(NSEvent *)theEvent;
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
685 -(void)rightMouseUp:(NSEvent *)theEvent;
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
686 -(void)otherMouseDown:(NSEvent *)theEvent;
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
687 -(void)otherMouseUp:(NSEvent *)theEvent;
723
37c8d2b4cec5 Initial key press event/signal handling... does not seem to trap on all controls...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 722
diff changeset
688 -(void)keyDown:(NSEvent *)theEvent;
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
689 -(void)setColor:(unsigned long)input;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
690 @end
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
691
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
692 @implementation DWBox
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
693 -(id)init
666
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
694 {
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
695 self = [super init];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
696
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
697 if (self)
666
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
698 {
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
699 box = calloc(1, sizeof(Box));
1453
4b516ef23b62 Boxes need to default to vertical on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1449
diff changeset
700 box->type = DW_VERT;
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
701 box->vsize = box->hsize = SIZEEXPAND;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
702 box->width = box->height = 1;
666
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
703 }
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
704 return self;
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
705 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
706 -(void)dealloc
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
707 {
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
708 UserData *root = userdata;
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
709 if(box->items)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
710 free(box->items);
666
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
711 free(box);
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
712 _remove_userdata(&root, NULL, TRUE);
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
713 dw_signal_disconnect_by_window(self);
666
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
714 [super dealloc];
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
715 }
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
716 -(Box *)box { return box; }
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
717 -(id)contentView { return self; }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
718 -(void *)userdata { return userdata; }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
719 -(void)setUserdata:(void *)input { userdata = input; }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
720 -(void)drawRect:(NSRect)rect
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
721 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
722 if(bgcolor)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
723 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
724 [bgcolor set];
755
f574028932cc Fix for crash when changing background colors, needed retain and release.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 754
diff changeset
725 NSRectFill([self bounds]);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
726 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
727 }
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
728 -(BOOL)isFlipped { return YES; }
701
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
729 -(void)mouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)1, 3); }
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
730 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)1, 4); }
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
731 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; }
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
732 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); }
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
733 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); }
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
734 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); }
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
735 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); }
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
736 -(void)setColor:(unsigned long)input
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
737 {
755
f574028932cc Fix for crash when changing background colors, needed retain and release.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 754
diff changeset
738 id orig = bgcolor;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
739
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
740 if(input == _colors[DW_CLR_DEFAULT])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
741 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
742 bgcolor = nil;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
743 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
744 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
745 {
755
f574028932cc Fix for crash when changing background colors, needed retain and release.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 754
diff changeset
746 bgcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(input)/255.0 green: DW_GREEN_VALUE(input)/255.0 blue: DW_BLUE_VALUE(input)/255.0 alpha: 1] retain];
812
f8bfb19090f9 dw_window_set_color() now affects boxes immediately (no longer on the next window refresh).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 811
diff changeset
747 [bgcolor set];
f8bfb19090f9 dw_window_set_color() now affects boxes immediately (no longer on the next window refresh).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 811
diff changeset
748 NSRectFill([self bounds]);
f8bfb19090f9 dw_window_set_color() now affects boxes immediately (no longer on the next window refresh).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 811
diff changeset
749 [self setNeedsDisplay:YES];
755
f574028932cc Fix for crash when changing background colors, needed retain and release.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 754
diff changeset
750 }
f574028932cc Fix for crash when changing background colors, needed retain and release.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 754
diff changeset
751 [orig release];
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
752 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
753 @end
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
754
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
755 /* Subclass for a group box type */
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
756 @interface DWGroupBox : NSBox
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
757 {
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
758 void *userdata;
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
759 NSColor *bgcolor;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
760 NSSize borderSize;
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
761 }
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
762 -(Box *)box;
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
763 -(void *)userdata;
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
764 -(void)setUserdata:(void *)input;
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
765 @end
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
766
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
767 @implementation DWGroupBox
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
768 -(Box *)box { return [[self contentView] box]; }
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
769 -(void *)userdata { return userdata; }
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
770 -(NSSize)borderSize { return borderSize; }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
771 -(NSSize)initBorder
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
772 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
773 NSSize frameSize = [self frame].size;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
774
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
775 if(frameSize.height < 20 || frameSize.width < 20)
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
776 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
777 frameSize.width = frameSize.height = 100;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
778 [self setFrameSize:frameSize];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
779 }
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
780 NSSize contentSize = [[self contentView] frame].size;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
781 NSSize titleSize = [self titleRect].size;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
782
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
783 borderSize.width = 100-contentSize.width;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
784 borderSize.height = (100-contentSize.height)-titleSize.height;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
785 return borderSize;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
786 }
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
787 -(void)setUserdata:(void *)input { userdata = input; }
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
788 @end
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
789
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
790 @interface DWWindow : NSWindow
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
791 {
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
792 int redraw;
1489
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
793 int shown;
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
794 }
898
bf2ca780f62d One more try at window key handling... since I can't seem to trap keyDown events in most places that get focus...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 895
diff changeset
795 -(void)sendEvent:(NSEvent *)theEvent;
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
796 -(void)keyDown:(NSEvent *)theEvent;
932
ed10b5284f36 Fixes for dw_window_capture(), dw_window_release() and motion notify events on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 931
diff changeset
797 -(void)mouseDragged:(NSEvent *)theEvent;
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
798 -(int)redraw;
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
799 -(void)setRedraw:(int)val;
1489
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
800 -(int)shown;
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
801 -(void)setShown:(int)val;
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
802 @end
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
803
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
804 @implementation DWWindow
1129
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
805 -(void)sendEvent:(NSEvent *)theEvent
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
806 {
1133
25bea6526ca1 Similar Mac fix to what I just commited on Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1130
diff changeset
807 int rcode = -1;
1129
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
808 if([theEvent type] == NSKeyDown)
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
809 {
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
810 rcode = _event_handler(self, theEvent, 2);
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
811 }
1133
25bea6526ca1 Similar Mac fix to what I just commited on Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1130
diff changeset
812 if ( rcode != TRUE )
1129
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
813 [super sendEvent:theEvent];
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
814 }
898
bf2ca780f62d One more try at window key handling... since I can't seem to trap keyDown events in most places that get focus...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 895
diff changeset
815 -(void)keyDown:(NSEvent *)theEvent { }
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
816 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); }
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
817 -(int)redraw { return redraw; }
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
818 -(void)setRedraw:(int)val { redraw = val; }
1489
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
819 -(int)shown { return shown; }
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
820 -(void)setShown:(int)val { shown = val; }
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
821 @end
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
822
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
823 /* Subclass for a render area type */
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
824 @interface DWRender : NSControl
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
825 {
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
826 void *userdata;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
827 NSFont *font;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
828 NSSize size;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
829 }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
830 -(void *)userdata;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
831 -(void)setUserdata:(void *)input;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
832 -(void)setFont:(NSFont *)input;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
833 -(NSFont *)font;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
834 -(void)setSize:(NSSize)input;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
835 -(NSSize)size;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
836 -(void)mouseDown:(NSEvent *)theEvent;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
837 -(void)mouseUp:(NSEvent *)theEvent;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
838 -(NSMenu *)menuForEvent:(NSEvent *)theEvent;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
839 -(void)rightMouseUp:(NSEvent *)theEvent;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
840 -(void)otherMouseDown:(NSEvent *)theEvent;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
841 -(void)otherMouseUp:(NSEvent *)theEvent;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
842 -(void)drawRect:(NSRect)rect;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
843 -(void)keyDown:(NSEvent *)theEvent;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
844 -(BOOL)isFlipped;
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
845 @end
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
846
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
847 @implementation DWRender
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
848 -(void *)userdata { return userdata; }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
849 -(void)setUserdata:(void *)input { userdata = input; }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
850 -(void)setFont:(NSFont *)input { [font release]; font = input; [font retain]; }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
851 -(NSFont *)font { return font; }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
852 -(void)setSize:(NSSize)input { size = input; }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
853 -(NSSize)size { return size; }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
854 -(void)mouseDown:(NSEvent *)theEvent
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
855 {
1652
202b1affc706 Fix taskbar/menubar event breakage from the recent Mac control key changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1650
diff changeset
856 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & NSControlKeyMask))
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
857 _event_handler(self, theEvent, 3);
1648
7a9b1189934a Another fix for Contol clicking on Mac... getting double events
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1647
diff changeset
858 }
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
859 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
860 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
861 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
862 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
863 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
864 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
865 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); }
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
866 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); }
954
cfb12bf3bb06 Fixes for some more coordinate system issues on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 953
diff changeset
867 -(BOOL)isFlipped { return YES; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
868 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; dw_signal_disconnect_by_window(self); [super dealloc]; }
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
869 -(BOOL)acceptsFirstResponder { return YES; }
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
870 @end
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
871
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
872 /* Subclass for a top-level window */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
873 @interface DWView : DWBox
854
d44bb4c4902d Fixed an error on the close event handler on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 853
diff changeset
874 #ifdef BUILDING_FOR_SNOW_LEOPARD
d44bb4c4902d Fixed an error on the close event handler on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 853
diff changeset
875 <NSWindowDelegate>
d44bb4c4902d Fixed an error on the close event handler on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 853
diff changeset
876 #endif
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
877 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
878 NSMenu *windowmenu;
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
879 NSSize oldsize;
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
880 }
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
881 -(BOOL)windowShouldClose:(id)sender;
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
882 -(void)setMenu:(NSMenu *)input;
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
883 -(void)windowDidBecomeMain:(id)sender;
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
884 -(void)menuHandler:(id)sender;
932
ed10b5284f36 Fixes for dw_window_capture(), dw_window_release() and motion notify events on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 931
diff changeset
885 -(void)mouseDragged:(NSEvent *)theEvent;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
886 @end
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
887
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
888 @implementation DWView
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
889 -(BOOL)windowShouldClose:(id)sender
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
890 {
1018
a943f973c3ff If there is no close event handler, the window should close by default on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 992
diff changeset
891 if(_event_handler(sender, nil, 6) > 0)
a943f973c3ff If there is no close event handler, the window should close by default on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 992
diff changeset
892 return NO;
a943f973c3ff If there is no close event handler, the window should close by default on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 992
diff changeset
893 return YES;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
894 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
895 - (void)viewDidMoveToWindow
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
896 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
897 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
898 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:[self window]];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
899 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
900 - (void)dealloc
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
901 {
736
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
902 if(windowmenu)
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
903 {
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
904 [windowmenu release];
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
905 }
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
906 [[NSNotificationCenter defaultCenter] removeObserver:self];
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
907 dw_signal_disconnect_by_window(self);
736
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
908 [super dealloc];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
909 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
910 - (void)windowResized:(NSNotification *)notification;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
911 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
912 NSSize size = [self frame].size;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
913
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
914 if(oldsize.width != size.width || oldsize.height != size.height)
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
915 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
916 _do_resize(box, size.width, size.height);
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
917 _event_handler([self window], nil, 1);
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
918 oldsize.width = size.width;
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
919 oldsize.height = size.height;
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
920 _handle_resize_events(box);
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
921 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
922 }
930
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
923 -(void)showWindow
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
924 {
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
925 NSSize size = [self frame].size;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
926
930
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
927 if(oldsize.width == size.width && oldsize.height == size.height)
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
928 {
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
929 _do_resize(box, size.width, size.height);
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
930 _handle_resize_events(box);
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
931 }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
932
930
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
933 }
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
934 -(void)windowDidBecomeMain:(id)sender
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
935 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
936 if(windowmenu)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
937 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
938 [DWApp setMainMenu:windowmenu];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
939 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
940 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
941 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
942 [DWApp setMainMenu:DWMainMenu];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
943 }
1026
f15dc5226c35 Fixed focus event was getting ignored because wrong handle passed to the event handler on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1023
diff changeset
944 _event_handler([self window], nil, 13);
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
945 }
736
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
946 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
947 -(void)menuHandler:(id)sender
1593
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
948 {
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
949 id menu = [sender menu];
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
950
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
951 /* Find the highest menu for this item */
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
952 while([menu supermenu])
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
953 {
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
954 menu = [menu supermenu];
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
955 }
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
956
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
957 /* Only perform the delay if this item is a child of the main menu */
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
958 if([DWApp mainMenu] == menu)
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
959 [DWObj performSelector:@selector(menuHandler:) withObject:sender afterDelay:0];
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
960 else
19af25f71e1f Yet another fix attempt for mene item issues on Mac 10.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1590
diff changeset
961 [DWObj menuHandler:sender];
1558
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
962 _dw_wakeup_app();
1522
c98b2ce2d5b2 Fix menuHandler not being called until an event on Mac 10.5. This reinstitutes the menu display bug on Leopard but that is only a cosmetic issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1517
diff changeset
963 }
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
964 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); }
952
abb9203adc05 Use NSCompositeSourceOver for bitblting that respects transparency of the source
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 951
diff changeset
965 -(void)mouseMoved:(NSEvent *)theEvent
abb9203adc05 Use NSCompositeSourceOver for bitblting that respects transparency of the source
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 951
diff changeset
966 {
944
cdb7a53e5515 Some motion notify changes... so it can handle events without the mouse button pressed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 943
diff changeset
967 id hit = [self hitTest:[theEvent locationInWindow]];
952
abb9203adc05 Use NSCompositeSourceOver for bitblting that respects transparency of the source
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 951
diff changeset
968
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
969 if([hit isMemberOfClass:[DWRender class]])
952
abb9203adc05 Use NSCompositeSourceOver for bitblting that respects transparency of the source
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 951
diff changeset
970 {
abb9203adc05 Use NSCompositeSourceOver for bitblting that respects transparency of the source
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 951
diff changeset
971 _event_handler(hit, theEvent, 5);
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
972 }
944
cdb7a53e5515 Some motion notify changes... so it can handle events without the mouse button pressed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 943
diff changeset
973 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
974 @end
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
975
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
976 /* Subclass for a button type */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
977 @interface DWButton : NSButton
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
978 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
979 void *userdata;
793
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
980 NSButtonType buttonType;
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
981 DWBox *parent;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
982 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
983 -(void *)userdata;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
984 -(void)setUserdata:(void *)input;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
985 -(void)buttonClicked:(id)sender;
793
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
986 -(void)setButtonType:(NSButtonType)input;
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
987 -(NSButtonType)buttonType;
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
988 -(void)setParent:(DWBox *)input;
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
989 -(DWBox *)parent;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
990 @end
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
991
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
992 @implementation DWButton
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
993 -(void *)userdata { return userdata; }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
994 -(void)setUserdata:(void *)input { userdata = input; }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
995 -(void)buttonClicked:(id)sender
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
996 {
793
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
997 _event_handler(self, nil, 8);
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
998 if([self buttonType] == NSRadioButton)
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
999 {
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1000 DWBox *viewbox = [self parent];
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1001 Box *thisbox = [viewbox box];
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1002 int z;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1003
793
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1004 for(z=0;z<thisbox->count;z++)
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1005 {
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1006 if(thisbox->items[z].type != TYPEBOX)
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1007 {
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1008 id object = thisbox->items[z].hwnd;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1009
793
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1010 if([object isMemberOfClass:[DWButton class]])
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1011 {
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1012 DWButton *button = object;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1013
793
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1014 if(button != self && [button buttonType] == NSRadioButton)
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1015 {
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1016 [button setState:NSOffState];
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1017 }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1018 }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1019 }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1020 }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1021 }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1022 }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1023 -(void)setButtonType:(NSButtonType)input { buttonType = input; [super setButtonType:input]; }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1024 -(NSButtonType)buttonType { return buttonType; }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1025 -(void)setParent:(DWBox *)input { parent = input; }
e328c7746cda Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 792
diff changeset
1026 -(DWBox *)parent { return parent; }
1806
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1027 -(void)keyDown:(NSEvent *)theEvent
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1028 {
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1029 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1030 if(vk == VK_RETURN || vk == VK_SPACE)
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1031 {
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1032 if(buttonType == NSSwitchButton)
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1033 [self setState:([self state] ? NSOffState : NSOnState)];
1807
d7447c814f8b Fix for selecting radio buttons with the keyboard on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1806
diff changeset
1034 else if(buttonType == NSRadioButton)
d7447c814f8b Fix for selecting radio buttons with the keyboard on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1806
diff changeset
1035 [self setState:NSOnState];
1806
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1036 [self buttonClicked:self];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1037 }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1038 else
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1039 {
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1040 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1041 [super keyDown:theEvent];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1042 }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1043 }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1044 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
1045 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1046 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1047 @end
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1048
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1049 /* Subclass for a progress type */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1050 @interface DWPercent : NSProgressIndicator
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1051 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1052 void *userdata;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1053 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1054 -(void *)userdata;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1055 -(void)setUserdata:(void *)input;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1056 @end
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1057
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1058 @implementation DWPercent
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1059 -(void *)userdata { return userdata; }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1060 -(void)setUserdata:(void *)input { userdata = input; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1061 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1062 @end
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1063
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1064 /* Subclass for a menu item type */
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1065 @implementation DWMenuItem
1517
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
1066 -(void)setCheck:(int)input { check = input; }
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
1067 -(int)check { return check; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1068 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1069 @end
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1070
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1071 /* Subclass for a scrollbox type */
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1072 @interface DWScrollBox : NSScrollView
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1073 {
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1074 void *userdata;
840
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
1075 id box;
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1076 }
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1077 -(void *)userdata;
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1078 -(void)setUserdata:(void *)input;
840
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
1079 -(void)setBox:(void *)input;
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
1080 -(id)box;
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1081 @end
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1082
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1083 @implementation DWScrollBox
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1084 -(void *)userdata { return userdata; }
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1085 -(void)setUserdata:(void *)input { userdata = input; }
840
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
1086 -(void)setBox:(void *)input { box = input; }
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
1087 -(id)box { return box; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1088 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1089 @end
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
1090
859
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1091 /* Subclass for a textfield that supports vertical centering */
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1092 @interface DWTextFieldCell : NSTextFieldCell
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1093 {
860
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1094 BOOL vcenter;
859
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1095 }
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1096 -(NSRect)drawingRectForBounds:(NSRect)theRect;
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1097 -(void)setVCenter:(BOOL)input;
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1098 @end
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1099
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1100 @implementation DWTextFieldCell
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1101 -(NSRect)drawingRectForBounds:(NSRect)theRect
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1102 {
860
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1103 /* Get the parent's idea of where we should draw */
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1104 NSRect newRect = [super drawingRectForBounds:theRect];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1105
859
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1106 /* If we are being vertically centered */
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1107 if(vcenter)
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1108 {
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1109 /* Get our ideal size for current text */
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1110 NSSize textSize = [self cellSizeForBounds:theRect];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1111
860
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1112 /* Center that in the proposed rect */
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1113 float heightDelta = newRect.size.height - textSize.height;
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1114 if (heightDelta > 0)
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1115 {
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1116 newRect.size.height -= heightDelta;
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1117 newRect.origin.y += (heightDelta / 2);
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1118 }
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1119 }
859
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1120
860
93ac372941c4 Formatting cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 859
diff changeset
1121 return newRect;
859
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1122 }
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1123 -(void)setVCenter:(BOOL)input { vcenter = input; }
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1124 @end
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
1125
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1126 @interface DWEntryFieldFormatter : NSFormatter
887
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1127 {
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1128 int maxLength;
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1129 }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1130 - (void)setMaximumLength:(int)len;
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1131 - (int)maximumLength;
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1132 @end
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1133
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1134 /* This formatter subclass will allow us to limit
887
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1135 * the text length in an entryfield.
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1136 */
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1137 @implementation DWEntryFieldFormatter
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1138 -(id)init
887
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1139 {
1063
2ebaea72ac95 Fix for some release calls causing issues on MacOS 10.7 Lion.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1061
diff changeset
1140 self = [super init];
887
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1141 maxLength = INT_MAX;
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1142 return self;
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1143 }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1144 -(void)setMaximumLength:(int)len { maxLength = len; }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1145 -(int)maximumLength { return maxLength; }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1146 -(NSString *)stringForObjectValue:(id)object { return (NSString *)object; }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1147 -(BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error { *object = string; return YES; }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1148 -(BOOL)isPartialStringValid:(NSString **)partialStringPtr
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1149 proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1150 originalString:(NSString *)origString
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1151 originalSelectedRange:(NSRange)origSelRange
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1152 errorDescription:(NSString **)error
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1153 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1154 if([*partialStringPtr length] > maxLength)
887
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1155 {
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1156 return NO;
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1157 }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1158 return YES;
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1159 }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1160 -(NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes { return nil; }
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1161 @end
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
1162
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1163 /* Subclass for a entryfield type */
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1164 @interface DWEntryField : NSTextField
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1165 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1166 void *userdata;
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1167 id clickDefault;
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1168 }
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1169 -(void *)userdata;
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1170 -(void)setUserdata:(void *)input;
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1171 -(void)setClickDefault:(id)input;
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1172 @end
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1173
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1174 @implementation DWEntryField
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1175 -(void *)userdata { return userdata; }
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1176 -(void)setUserdata:(void *)input { userdata = input; }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1177 -(void)setClickDefault:(id)input { clickDefault = input; }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1178 -(void)keyUp:(NSEvent *)theEvent
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1179 {
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1180 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1181 if(clickDefault && vk == VK_RETURN)
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1182 {
1236
46de4dbe710d Fixed clickdefault not triggering event for buttons on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1235
diff changeset
1183 if([clickDefault isKindOfClass:[NSButton class]])
46de4dbe710d Fixed clickdefault not triggering event for buttons on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1235
diff changeset
1184 [clickDefault buttonClicked:self];
46de4dbe710d Fixed clickdefault not triggering event for buttons on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1235
diff changeset
1185 else
46de4dbe710d Fixed clickdefault not triggering event for buttons on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1235
diff changeset
1186 [[self window] makeFirstResponder:clickDefault];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1187 } else
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1188 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1189 [super keyUp:theEvent];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1190 }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1191 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1192 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1193 {
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1194 if(([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask)
1235
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1195 {
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1196 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"])
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1197 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1198 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"])
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1199 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1200 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"v"])
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1201 return [NSApp sendAction:@selector(paste:) to:[[self window] firstResponder] from:self];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1202 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"])
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1203 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1204 }
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1205 return [super performKeyEquivalent:theEvent];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1206 }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1207 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1208 @end
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1209
1564
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1210 /* Subclass for a text and status text type */
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1211 @interface DWText : NSTextField
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1212 {
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1213 void *userdata;
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1214 id clickDefault;
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1215 }
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1216 -(void *)userdata;
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1217 -(void)setUserdata:(void *)input;
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1218 @end
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1219
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1220 @implementation DWText
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1221 -(void *)userdata { return userdata; }
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1222 -(void)setUserdata:(void *)input { userdata = input; }
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1223 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1224 @end
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1225
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
1226
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1227 /* Subclass for a entryfield password type */
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1228 @interface DWEntryFieldPassword : NSSecureTextField
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1229 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1230 void *userdata;
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1231 id clickDefault;
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1232 }
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1233 -(void *)userdata;
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1234 -(void)setUserdata:(void *)input;
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1235 -(void)setClickDefault:(id)input;
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1236 @end
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1237
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1238 @implementation DWEntryFieldPassword
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1239 -(void *)userdata { return userdata; }
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1240 -(void)setUserdata:(void *)input { userdata = input; }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1241 -(void)setClickDefault:(id)input { clickDefault = input; }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1242 -(void)keyUp:(NSEvent *)theEvent
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1243 {
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1244 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1245 {
1236
46de4dbe710d Fixed clickdefault not triggering event for buttons on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1235
diff changeset
1246 if([clickDefault isKindOfClass:[NSButton class]])
46de4dbe710d Fixed clickdefault not triggering event for buttons on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1235
diff changeset
1247 [clickDefault buttonClicked:self];
46de4dbe710d Fixed clickdefault not triggering event for buttons on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1235
diff changeset
1248 else
46de4dbe710d Fixed clickdefault not triggering event for buttons on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1235
diff changeset
1249 [[self window] makeFirstResponder:clickDefault];
1235
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1250 }
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1251 else
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1252 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1253 [super keyUp:theEvent];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1254 }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
1255 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1256 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1257 {
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1258 if(([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask)
1235
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1259 {
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1260 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"])
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1261 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1262 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"])
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1263 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1264 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"v"])
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1265 return [NSApp sendAction:@selector(paste:) to:[[self window] firstResponder] from:self];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1266 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"])
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1267 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1268 }
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1269 return [super performKeyEquivalent:theEvent];
9327f684c9b8 Attempt at fixing Copy, Cut, Paste, Select All Mac key combos...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1234
diff changeset
1270 }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1271 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1272 @end
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
1273
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1274 /* Subclass for a Notebook control type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1275 @interface DWNotebook : NSTabView
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
1276 #ifdef BUILDING_FOR_SNOW_LEOPARD
717
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
1277 <NSTabViewDelegate>
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
1278 #endif
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1279 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1280 void *userdata;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1281 int pageid;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1282 }
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1283 -(void *)userdata;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1284 -(void)setUserdata:(void *)input;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1285 -(int)pageid;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1286 -(void)setPageid:(int)input;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1287 -(void)tabView:(NSTabView *)notebook didSelectTabViewItem:(NSTabViewItem *)notepage;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1288 @end
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1289
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1290 /* Subclass for a Notebook page type */
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1291 @interface DWNotebookPage : NSTabViewItem
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1292 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1293 void *userdata;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1294 int pageid;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1295 }
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1296 -(void *)userdata;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1297 -(void)setUserdata:(void *)input;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1298 -(int)pageid;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1299 -(void)setPageid:(int)input;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1300 @end
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1301
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1302 @implementation DWNotebook
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1303 -(void *)userdata { return userdata; }
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1304 -(void)setUserdata:(void *)input { userdata = input; }
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1305 -(int)pageid { return pageid; }
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1306 -(void)setPageid:(int)input { pageid = input; }
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1307 -(void)tabView:(NSTabView *)notebook didSelectTabViewItem:(NSTabViewItem *)notepage
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1308 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1309 id object = [notepage view];
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1310 DWNotebookPage *page = (DWNotebookPage *)notepage;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1311
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1312 if([object isMemberOfClass:[DWBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1313 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1314 DWBox *view = object;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1315 Box *box = [view box];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1316 NSSize size = [view frame].size;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1317 _do_resize(box, size.width, size.height);
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
1318 _handle_resize_events(box);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1319 }
1102
cfe7d2b6bc16 Added DW_INT_TO_POINTER/DW_UINT_TO_POINTER/DW_POINTER_TO_INT/DW_POINTER_TO_UINT macros.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1101
diff changeset
1320 _event_handler(self, DW_INT_TO_POINTER([page pageid]), 15);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1321 }
1808
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1322 -(void)keyDown:(NSEvent *)theEvent
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1323 {
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1324 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
1819
d784b85b632e Change incorrect call to DW_MUTEX_LOCK to DW_MUTEX_UNLOCK in dw_mle_get_size()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1809
diff changeset
1325
1809
5efaea897310 Fixed back tab handling for certain controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1808
diff changeset
1326 if(vk == NSTabCharacter || vk == NSBackTabCharacter)
1808
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1327 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
1809
5efaea897310 Fixed back tab handling for certain controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1808
diff changeset
1328 else if(vk == NSLeftArrowFunctionKey)
1808
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1329 {
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1330 NSArray *pages = [self tabViewItems];
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1331 DWNotebookPage *page = (DWNotebookPage *)[self selectedTabViewItem];
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1332 NSUInteger index = [pages indexOfObject:page];
1819
d784b85b632e Change incorrect call to DW_MUTEX_LOCK to DW_MUTEX_UNLOCK in dw_mle_get_size()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1809
diff changeset
1333
1808
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1334 if(index != NSNotFound)
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1335 {
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1336 if(index > 0)
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1337 [self selectTabViewItem:[pages objectAtIndex:(index-1)]];
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1338 else
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1339 [self selectTabViewItem:[pages objectAtIndex:0]];
1819
d784b85b632e Change incorrect call to DW_MUTEX_LOCK to DW_MUTEX_UNLOCK in dw_mle_get_size()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1809
diff changeset
1340
1808
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1341 }
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1342 }
1809
5efaea897310 Fixed back tab handling for certain controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1808
diff changeset
1343 else if(vk == NSRightArrowFunctionKey)
1808
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1344 {
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1345 NSArray *pages = [self tabViewItems];
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1346 DWNotebookPage *page = (DWNotebookPage *)[self selectedTabViewItem];
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1347 NSUInteger index = [pages indexOfObject:page];
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1348 NSUInteger count = [pages count];
1819
d784b85b632e Change incorrect call to DW_MUTEX_LOCK to DW_MUTEX_UNLOCK in dw_mle_get_size()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1809
diff changeset
1349
1808
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1350 if(index != NSNotFound)
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1351 {
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1352 if(index + 1 < count)
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1353 [self selectTabViewItem:[pages objectAtIndex:(index+1)]];
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1354 else
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1355 [self selectTabViewItem:[pages objectAtIndex:(count-1)]];
1819
d784b85b632e Change incorrect call to DW_MUTEX_LOCK to DW_MUTEX_UNLOCK in dw_mle_get_size()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1809
diff changeset
1356
1808
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1357 }
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1358 }
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1359 [super keyDown:theEvent];
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1360 }
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1361 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
f3458cd6277c Added keyboard support to the notebook control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1807
diff changeset
1362 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1363 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1364 @end
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
1365
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1366 @implementation DWNotebookPage
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1367 -(void *)userdata { return userdata; }
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1368 -(void)setUserdata:(void *)input { userdata = input; }
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1369 -(int)pageid { return pageid; }
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1370 -(void)setPageid:(int)input { pageid = input; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1371 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1372 @end
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1373
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1374 /* Subclass for a color chooser type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1375 @interface DWColorChoose : NSColorPanel
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1376 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1377 DWDialog *dialog;
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
1378 NSColor *pickedcolor;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1379 }
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1380 -(void)changeColor:(id)sender;
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1381 -(void)setDialog:(DWDialog *)input;
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
1382 -(DWDialog *)dialog;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1383 @end
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1384
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1385 @implementation DWColorChoose
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1386 -(void)changeColor:(id)sender
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1387 {
1644
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
1388 if(!dialog)
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
1389 [self close];
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
1390 else
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1391 pickedcolor = [self color];
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1392 }
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1393 -(BOOL)windowShouldClose:(id)window
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1394 {
1644
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
1395 if(dialog)
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
1396 {
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1397 DWDialog *d = dialog;
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1398 dialog = nil;
1644
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
1399 dw_dialog_dismiss(d, pickedcolor);
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
1400 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1401 [self close];
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1402 return NO;
1644
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
1403 }
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1404 -(void)setDialog:(DWDialog *)input { dialog = input; }
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
1405 -(DWDialog *)dialog { return dialog; }
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1406 @end
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1407
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1408 /* Subclass for a font chooser type */
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1409 @interface DWFontChoose : NSFontPanel
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1410 {
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1411 DWDialog *dialog;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1412 NSFontManager *fontManager;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1413 }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1414 -(void)setDialog:(DWDialog *)input;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1415 -(void)setFontManager:(NSFontManager *)input;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1416 -(DWDialog *)dialog;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1417 @end
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1418
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1419 @implementation DWFontChoose
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
1420 -(BOOL)windowShouldClose:(id)window
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
1421 {
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1422 DWDialog *d = dialog; dialog = nil;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1423 NSFont *pickedfont = [fontManager selectedFont];
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
1424 dw_dialog_dismiss(d, pickedfont);
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
1425 [window orderOut:nil];
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
1426 return NO;
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1427 }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1428 -(void)setDialog:(DWDialog *)input { dialog = input; }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1429 -(void)setFontManager:(NSFontManager *)input { fontManager = input; }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1430 -(DWDialog *)dialog { return dialog; }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1431 @end
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
1432
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1433 /* Subclass for a splitbar type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1434 @interface DWSplitBar : NSSplitView
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
1435 #ifdef BUILDING_FOR_SNOW_LEOPARD
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1436 <NSSplitViewDelegate>
717
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
1437 #endif
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1438 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1439 void *userdata;
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1440 float percent;
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1441 }
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1442 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification;
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1443 -(void *)userdata;
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1444 -(void)setUserdata:(void *)input;
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1445 -(float)percent;
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1446 -(void)setPercent:(float)input;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1447 @end
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1448
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1449 @implementation DWSplitBar
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1450 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1451 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1452 NSArray *views = [self subviews];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1453 id object;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1454
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1455 for(object in views)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1456 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1457 if([object isMemberOfClass:[DWBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1458 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1459 DWBox *view = object;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1460 Box *box = [view box];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1461 NSSize size = [view frame].size;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1462 _do_resize(box, size.width, size.height);
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
1463 _handle_resize_events(box);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1464 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1465 }
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1466 }
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1467 -(void *)userdata { return userdata; }
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1468 -(void)setUserdata:(void *)input { userdata = input; }
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1469 -(float)percent { return percent; }
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
1470 -(void)setPercent:(float)input { percent = input; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1471 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1472 @end
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
1473
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1474 /* Subclass for a slider type */
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1475 @interface DWSlider : NSSlider
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1476 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1477 void *userdata;
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1478 }
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1479 -(void *)userdata;
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1480 -(void)setUserdata:(void *)input;
704
336800e9e648 Fixes to the slider control so events happen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 703
diff changeset
1481 -(void)sliderChanged:(id)sender;
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1482 @end
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1483
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1484 @implementation DWSlider
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1485 -(void *)userdata { return userdata; }
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1486 -(void)setUserdata:(void *)input { userdata = input; }
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
1487 -(void)sliderChanged:(id)sender { _event_handler(self, (void *)[self integerValue], 14); }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1488 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1489 @end
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1490
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1491 /* Subclass for a slider type */
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1492 @interface DWScrollbar : NSScroller
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1493 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1494 void *userdata;
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1495 double range;
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1496 double visible;
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
1497 int vertical;
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1498 }
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1499 -(void *)userdata;
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1500 -(void)setUserdata:(void *)input;
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1501 -(float)range;
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1502 -(float)visible;
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
1503 -(int)vertical;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
1504 -(void)setVertical:(int)value;
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1505 -(void)setRange:(double)input1 andVisible:(double)input2;
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
1506 -(void)scrollerChanged:(id)sender;
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1507 @end
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1508
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1509 @implementation DWScrollbar
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1510 -(void *)userdata { return userdata; }
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1511 -(void)setUserdata:(void *)input { userdata = input; }
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1512 -(float)range { return range; }
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1513 -(float)visible { return visible; }
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
1514 -(int)vertical { return vertical; }
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
1515 -(void)setVertical:(int)value { vertical = value; }
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1516 -(void)setRange:(double)input1 andVisible:(double)input2 { range = input1; visible = input2; }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1517 -(void)scrollerChanged:(id)sender
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1518 {
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1519 double max = (range - visible);
923
0ac67b62b594 Fix int to double conversion issues causing scrollbar issues on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 922
diff changeset
1520 double result = ([self doubleValue] * max);
0ac67b62b594 Fix int to double conversion issues causing scrollbar issues on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 922
diff changeset
1521 double newpos = result;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
1522
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1523 switch ([sender hitPart])
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1524 {
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1525
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1526 case NSScrollerDecrementLine:
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1527 if(newpos > 0)
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1528 {
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1529 newpos--;
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1530 }
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1531 break;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1532
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1533 case NSScrollerIncrementLine:
712
01107d8e033e Fixed the scrollbar maximum range to be correct. Also added some MLE code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 711
diff changeset
1534 if(newpos < max)
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1535 {
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1536 newpos++;
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1537 }
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1538 break;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1539
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1540 case NSScrollerDecrementPage:
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1541 newpos -= visible;
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1542 if(newpos < 0)
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1543 {
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1544 newpos = 0;
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1545 }
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1546 break;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1547
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1548 case NSScrollerIncrementPage:
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1549 newpos += visible;
712
01107d8e033e Fixed the scrollbar maximum range to be correct. Also added some MLE code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 711
diff changeset
1550 if(newpos > max)
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1551 {
712
01107d8e033e Fixed the scrollbar maximum range to be correct. Also added some MLE code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 711
diff changeset
1552 newpos = max;
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1553 }
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1554 break;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1555
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1556 default:
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
1557 ; /* do nothing */
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1558 }
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1559 int newposi = (int)newpos;
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
1560 newpos = (newpos - (double)newposi) > 0.5 ? (double)(newposi + 1) : (double)newposi;
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1561 if(newpos != result)
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1562 {
923
0ac67b62b594 Fix int to double conversion issues causing scrollbar issues on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 922
diff changeset
1563 [self setDoubleValue:(newpos/max)];
0ac67b62b594 Fix int to double conversion issues causing scrollbar issues on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 922
diff changeset
1564 }
1102
cfe7d2b6bc16 Added DW_INT_TO_POINTER/DW_UINT_TO_POINTER/DW_POINTER_TO_INT/DW_POINTER_TO_UINT macros.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1101
diff changeset
1565 _event_handler(self, DW_INT_TO_POINTER((int)newpos), 14);
707
86d76fc09237 Added support for scrollbar line and page scrolling. Need to check the calculations...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 706
diff changeset
1566 }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1567 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1568 @end
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1569
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1570 /* Subclass for a MLE type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1571 @interface DWMLE : NSTextView
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1572 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1573 void *userdata;
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
1574 id scrollview;
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1575 }
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1576 -(void *)userdata;
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1577 -(void)setUserdata:(void *)input;
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
1578 -(id)scrollview;
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
1579 -(void)setScrollview:(id)input;
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1580 @end
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1581
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1582 @implementation DWMLE
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1583 -(void *)userdata { return userdata; }
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1584 -(void)setUserdata:(void *)input { userdata = input; }
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
1585 -(id)scrollview { return scrollview; }
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
1586 -(void)setScrollview:(id)input { scrollview = input; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
1587 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
653
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1588 @end
36c6669422d2 Continuing to add types... looking to almost be usable. :)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 652
diff changeset
1589
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1590 /* Subclass NSTextFieldCell for displaying image and text */
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1591 @interface DWImageAndTextCell : NSTextFieldCell
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1592 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1593 @private
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1594 NSImage *image;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1595 }
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1596 -(void)setImage:(NSImage *)anImage;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1597 -(NSImage *)image;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1598 -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1599 -(NSSize)cellSize;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1600 @end
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1601
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1602 @implementation DWImageAndTextCell
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1603 -(void)dealloc
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1604 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1605 [image release];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1606 image = nil;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1607 [super dealloc];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1608 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1609 -copyWithZone:(NSZone *)zone
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1610 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1611 DWImageAndTextCell *cell = (DWImageAndTextCell *)[super copyWithZone:zone];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1612 cell->image = [image retain];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1613 return cell;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1614 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1615 -(void)setImage:(NSImage *)anImage
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1616 {
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1617 if(anImage != image)
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1618 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1619 [image release];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1620 image = [anImage retain];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1621 }
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1622 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1623 -(NSImage *)image
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1624 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1625 return [[image retain] autorelease];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1626 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1627 -(NSRect)imageFrameForCellFrame:(NSRect)cellFrame
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1628 {
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1629 if(image != nil)
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1630 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1631 NSRect imageFrame;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1632 imageFrame.size = [image size];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1633 imageFrame.origin = cellFrame.origin;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1634 imageFrame.origin.x += 3;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1635 imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1636 return imageFrame;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1637 }
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1638 else
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1639 return NSZeroRect;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1640 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1641 -(void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1642 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1643 NSRect textFrame, imageFrame;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1644 NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1645 [super editWithFrame: textFrame inView: controlView editor:textObj delegate:anObject event: theEvent];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1646 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1647 -(void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1648 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1649 NSRect textFrame, imageFrame;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1650 NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1651 [super selectWithFrame: textFrame inView: controlView editor:textObj delegate:anObject start:selStart length:selLength];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1652 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1653 -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1654 {
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1655 if(image != nil)
1210
5a016a5a7412 Slight change in design behavior for dw_container_set_row_bg()...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1206
diff changeset
1656 {
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1657 NSSize imageSize;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1658 NSRect imageFrame;
1779
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1659 SEL sdir = NSSelectorFromString(@"drawInRect:fromRect:operation:fraction:respectFlipped:hints:");
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1660
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1661 imageSize = [image size];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1662 NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1663 if ([self drawsBackground])
1210
5a016a5a7412 Slight change in design behavior for dw_container_set_row_bg()...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1206
diff changeset
1664 {
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1665 [[self backgroundColor] set];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1666 NSRectFill(imageFrame);
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1667 }
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1668 imageFrame.origin.x += 3;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1669 imageFrame.size = imageSize;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1670
1779
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1671 /* New method for 10.6 and later */
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1672 if([image respondsToSelector:sdir])
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1673 {
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1674 IMP idir = [image methodForSelector:sdir];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1675
1779
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1676 imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1677
1779
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1678 idir(image, sdir, imageFrame, NSZeroRect, NSCompositeSourceOver, 1.0, YES, nil);
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1679 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1680 else
1779
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1681 {
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1682 /* Old method for 10.5 */
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1683 SEL sctp = NSSelectorFromString(@"compositeToPoint:operation:");
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1684
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1685 if ([controlView isFlipped])
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1686 imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2);
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1687 else
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1688 imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1689
1779
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1690 if([image respondsToSelector:sctp])
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1691 {
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1692 IMP ictp = [image methodForSelector:sctp];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1693
1779
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1694 ictp(image, sctp, imageFrame.origin, NSCompositeSourceOver);
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1695 }
f77b76c86d19 Readd support for 10.5... the drawInRect method I was using only supports 10.6 and higher...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1778
diff changeset
1696 }
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1697 }
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1698 [super drawWithFrame:cellFrame inView:controlView];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1699 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1700 -(NSSize)cellSize
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1701 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1702 NSSize cellSize = [super cellSize];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1703 cellSize.width += (image ? [image size].width : 0) + 3;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1704 return cellSize;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1705 }
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1706 @end
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1707
655
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
1708 /* Subclass for a Container/List type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1709 @interface DWContainer : NSTableView
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
1710 #ifdef BUILDING_FOR_SNOW_LEOPARD
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
1711 <NSTableViewDataSource,NSTableViewDelegate>
717
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
1712 #endif
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
1713 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1714 void *userdata;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1715 NSMutableArray *tvcols;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1716 NSMutableArray *data;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1717 NSMutableArray *types;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1718 NSPointerArray *titles;
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1719 NSColor *fgcolor, *oddcolor, *evencolor;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1720 int lastAddPoint, lastQueryPoint;
668
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
1721 id scrollview;
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
1722 int filesystem;
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1723 }
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1724 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable;
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1725 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow;
708
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
1726 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
1727 -(void *)userdata;
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
1728 -(void)setUserdata:(void *)input;
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
1729 -(void)setFilesystem:(int)input;
831
168b9db65825 Minor fix for dw_container_column_set_width() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 829
diff changeset
1730 -(int)filesystem;
668
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
1731 -(id)scrollview;
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
1732 -(void)setScrollview:(id)input;
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1733 -(void)addColumn:(NSTableColumn *)input andType:(int)type;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
1734 -(NSTableColumn *)getColumn:(int)col;
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1735 -(int)addRow:(NSArray *)input;
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1736 -(int)addRows:(int)number;
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
1737 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1738 -(void)editCell:(id)input at:(int)row and:(int)col;
662
d7badd5606ca Removed the Carbon source file, and changes to configure to build the Cocoa version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 661
diff changeset
1739 -(void)removeRow:(int)row;
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
1740 -(void)setRow:(int)row title:(void *)input;
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
1741 -(void *)getRowTitle:(int)row;
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
1742 -(id)getRow:(int)row and:(int)col;
662
d7badd5606ca Removed the Carbon source file, and changes to configure to build the Cocoa version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 661
diff changeset
1743 -(int)cellType:(int)col;
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1744 -(int)lastAddPoint;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
1745 -(int)lastQueryPoint;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
1746 -(void)setLastQueryPoint:(int)input;
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1747 -(void)clear;
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1748 -(void)setup;
856
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
1749 -(void)optimize;
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1750 -(NSSize)getsize;
810
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
1751 -(void)setForegroundColor:(NSColor *)input;
708
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
1752 -(void)doubleClicked:(id)sender;
829
f7b6c88bac47 Implemented Enter/Return triggering the item enter event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 828
diff changeset
1753 -(void)keyUp:(NSEvent *)theEvent;
867
139acecd6ca0 Guess I wanted to trap didClickTableColumn instead of mouseDownInHeaderOfTableColumn to avoid spurious events.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 866
diff changeset
1754 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn;
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
1755 -(void)selectionChanged:(id)sender;
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
1756 -(NSMenu *)menuForEvent:(NSEvent *)event;
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
1757 @end
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
1758
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
1759 @implementation DWContainer
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1760 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1761 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1762 if(tvcols && data)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1763 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1764 int cols = (int)[tvcols count];
1134
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1765 int total = (int)[data count];
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1766 if(cols && total)
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1767 {
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1768 return total / cols;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1769 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1770 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1771 return 0;
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1772 }
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1773 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1774 {
1134
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1775 if(tvcols && data)
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1776 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1777 int z, col = -1;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1778 int count = (int)[tvcols count];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1779
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1780 for(z=0;z<count;z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1781 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1782 if([tvcols objectAtIndex:z] == aCol)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1783 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1784 col = z;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1785 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1786 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1787 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1788 if(col != -1)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1789 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1790 int index = (int)(aRow * count) + col;
1134
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1791 if(index < [data count])
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1792 {
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1793 id this = [data objectAtIndex:index];
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1794 return ([this isKindOfClass:[NSNull class]]) ? nil : this;
41a93f9896e3 Avoid an array out of bounds after container clear on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1133
diff changeset
1795 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1796 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1797 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1798 return nil;
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1799 }
708
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
1800 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; }
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1801 -(void *)userdata { return userdata; }
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1802 -(void)setUserdata:(void *)input { userdata = input; }
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
1803 -(void)setFilesystem:(int)input { filesystem = input; }
831
168b9db65825 Minor fix for dw_container_column_set_width() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 829
diff changeset
1804 -(int)filesystem { return filesystem; }
717
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
1805 -(id)scrollview { return scrollview; }
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
1806 -(void)setScrollview:(id)input { scrollview = input; }
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1807 -(void)addColumn:(NSTableColumn *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } }
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
1808 -(NSTableColumn *)getColumn:(int)col { if(tvcols) { return [tvcols objectAtIndex:col]; } return nil; }
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1809 -(void)setRowBgOdd:(unsigned long)oddcol andEven:(unsigned long)evencol
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1810 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1811 NSColor *oldodd = oddcolor;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1812 NSColor *oldeven = evencolor;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1813 unsigned long _odd = _get_color(oddcol);
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1814 unsigned long _even = _get_color(evencol);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1815
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1816 /* Get the NSColor for non-default colors */
1210
5a016a5a7412 Slight change in design behavior for dw_container_set_row_bg()...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1206
diff changeset
1817 if(oddcol != DW_RGB_TRANSPARENT)
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1818 oddcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_odd)/255.0 green: DW_GREEN_VALUE(_odd)/255.0 blue: DW_BLUE_VALUE(_odd)/255.0 alpha: 1] retain];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1819 else
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1820 oddcolor = NULL;
1210
5a016a5a7412 Slight change in design behavior for dw_container_set_row_bg()...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1206
diff changeset
1821 if(evencol != DW_RGB_TRANSPARENT)
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1822 evencolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_even)/255.0 green: DW_GREEN_VALUE(_even)/255.0 blue: DW_BLUE_VALUE(_even)/255.0 alpha: 1] retain];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1823 else
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1824 evencolor = NULL;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1825 [oldodd release];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1826 [oldeven release];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1827 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1828 -(int)insertRow:(NSArray *)input at:(int)index
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1829 {
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1830 if(data)
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1831 {
687
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
1832 unsigned long start = [tvcols count] * index;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1833 NSIndexSet *set = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(start, start + [tvcols count])];
687
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
1834 if(index < lastAddPoint)
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
1835 {
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
1836 lastAddPoint++;
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
1837 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1838 [data insertObjects:input atIndexes:set];
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1839 [titles insertPointer:NULL atIndex:index];
687
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
1840 [set release];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1841 return (int)[titles count];
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1842 }
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1843 return 0;
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1844 }
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1845 -(int)addRow:(NSArray *)input
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1846 {
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1847 if(data)
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1848 {
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1849 lastAddPoint = (int)[titles count];
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1850 [data addObjectsFromArray:input];
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1851 [titles addPointer:NULL];
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1852 return (int)[titles count];
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1853 }
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1854 return 0;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
1855 }
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1856 -(int)addRows:(int)number
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1857 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1858 if(tvcols)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1859 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1860 int count = (int)(number * [tvcols count]);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1861 int z;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1862
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1863 lastAddPoint = (int)[titles count];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1864
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1865 for(z=0;z<count;z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1866 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1867 [data addObject:[NSNull null]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1868 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1869 for(z=0;z<number;z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1870 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1871 [titles addPointer:NULL];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1872 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1873 return (int)[titles count];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1874 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1875 return 0;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1876 }
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
1877 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
1878 {
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1879 DWImageAndTextCell *bcell = cell;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1880
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1881 /* Handle drawing image and text if necessary */
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1882 if([cell isMemberOfClass:[DWImageAndTextCell class]])
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
1883 {
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
1884 int index = (int)(row * [tvcols count]);
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1885 DWImageAndTextCell *browsercell = [data objectAtIndex:index];
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
1886 NSImage *img = [browsercell image];
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1887 [bcell setImage:img];
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1888 }
1215
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1889 if([cell isKindOfClass:[NSTextFieldCell class]])
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1890 {
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1891 /* Handle drawing alternating row colors if enabled */
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1892 if ((row % 2) == 0)
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1893 {
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1894 if(evencolor)
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1895 {
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1896 [bcell setDrawsBackground:YES];
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1897 [bcell setBackgroundColor:evencolor];
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1898 }
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1899 else
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1900 [bcell setDrawsBackground:NO];
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1901 }
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
1902 else
1215
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1903 {
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1904 if(oddcolor)
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1905 {
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1906 [bcell setDrawsBackground:YES];
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1907 [bcell setBackgroundColor:oddcolor];
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1908 }
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1909 else
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1910 [bcell setDrawsBackground:NO];
dc8ea09605f7 Can't set the background on Image cells apparently on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1212
diff changeset
1911 }
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
1912 }
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
1913 }
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1914 -(void)editCell:(id)input at:(int)row and:(int)col
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1915 {
1288
d10969835d2d Changes to allow removing icon on BITMAPORICON container columns on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1279
diff changeset
1916 if(tvcols)
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1917 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1918 int index = (int)(row * [tvcols count]) + col;
934
13384e89964c Put in a bounds check just on a hunch when editing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 933
diff changeset
1919 if(index < [data count])
13384e89964c Put in a bounds check just on a hunch when editing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 933
diff changeset
1920 {
1288
d10969835d2d Changes to allow removing icon on BITMAPORICON container columns on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1279
diff changeset
1921 if(!input)
d10969835d2d Changes to allow removing icon on BITMAPORICON container columns on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1279
diff changeset
1922 input = [NSNull null];
934
13384e89964c Put in a bounds check just on a hunch when editing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 933
diff changeset
1923 [data replaceObjectAtIndex:index withObject:input];
13384e89964c Put in a bounds check just on a hunch when editing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 933
diff changeset
1924 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1925 }
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
1926 }
662
d7badd5606ca Removed the Carbon source file, and changes to configure to build the Cocoa version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 661
diff changeset
1927 -(void)removeRow:(int)row
d7badd5606ca Removed the Carbon source file, and changes to configure to build the Cocoa version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 661
diff changeset
1928 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1929 if(tvcols)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1930 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1931 int z, start, end;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1932 int count = (int)[tvcols count];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1933
1705
3fa0448d3a7e Fixed a bug in dw_container_delete_row() on Mac and potentially a similar bug in dw_container_delete().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1704
diff changeset
1934 start = (count * row);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1935 end = start + count;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
1936
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1937 for(z=start;z<end;z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1938 {
1705
3fa0448d3a7e Fixed a bug in dw_container_delete_row() on Mac and potentially a similar bug in dw_container_delete().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1704
diff changeset
1939 [data removeObjectAtIndex:start];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1940 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1941 [titles removePointerAtIndex:row];
1705
3fa0448d3a7e Fixed a bug in dw_container_delete_row() on Mac and potentially a similar bug in dw_container_delete().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1704
diff changeset
1942 if(lastAddPoint > 0 && lastAddPoint > row)
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1943 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1944 lastAddPoint--;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1945 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1946 }
662
d7badd5606ca Removed the Carbon source file, and changes to configure to build the Cocoa version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 661
diff changeset
1947 }
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
1948 -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } }
683
7385011c3327 Fixed a minor issue causing crashes when right clicking on an empty container.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 682
diff changeset
1949 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
1950 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; }
662
d7badd5606ca Removed the Carbon source file, and changes to configure to build the Cocoa version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 661
diff changeset
1951 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; }
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
1952 -(int)lastAddPoint { return lastAddPoint; }
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
1953 -(int)lastQueryPoint { return lastQueryPoint; }
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
1954 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; }
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
1955 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1956 -(void)setup
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
1957 {
1774
4cc999e757a3 Check for pointerArrayWithWeakObjects before weakObjectsPointerArray on Mac
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1773
diff changeset
1958 SEL swopa = NSSelectorFromString(@"pointerArrayWithWeakObjects");
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
1959
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
1960 if(![[NSPointerArray class] respondsToSelector:swopa])
1774
4cc999e757a3 Check for pointerArrayWithWeakObjects before weakObjectsPointerArray on Mac
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1773
diff changeset
1961 swopa = NSSelectorFromString(@"weakObjectsPointerArray");
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
1962 if(![[NSPointerArray class] respondsToSelector:swopa])
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
1963 return;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1964
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
1965 IMP iwopa = [[NSPointerArray class] methodForSelector:swopa];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1966
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
1967 titles = iwopa([NSPointerArray class], swopa);
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
1968 [titles retain];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1969 tvcols = [[[NSMutableArray alloc] init] retain];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1970 data = [[[NSMutableArray alloc] init] retain];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1971 types = [[[NSMutableArray alloc] init] retain];
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
1972
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
1973 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self];
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
1974 }
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1975 -(NSSize)getsize
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1976 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1977 int cwidth = 0, cheight = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1978
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1979 if(tvcols)
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1980 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1981 int z;
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1982 int colcount = (int)[tvcols count];
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1983 int rowcount = (int)[self numberOfRowsInTableView:self];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1984
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1985 for(z=0;z<colcount;z++)
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1986 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1987 NSTableColumn *column = [tvcols objectAtIndex:z];
1574
ae5e322584cd Use [NSTableColumn width] method to get header width on Mac instead of frame size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1573
diff changeset
1988 int width = [column width];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1989
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1990 if(rowcount > 0)
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1991 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1992 int x;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1993
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1994 for(x=0;x<rowcount;x++)
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1995 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1996 NSCell *cell = [self preparedCellAtColumn:z row:x];
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1997 int thiswidth = [cell cellSize].width;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
1998
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
1999 /* If on the first column... add up the heights */
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2000 if(z == 0)
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2001 cheight += [cell cellSize].height;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2002
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2003 /* Check the image inside the cell to get its width */
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2004 if([cell isMemberOfClass:[NSImageCell class]])
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2005 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2006 int index = (int)(x * [tvcols count]) + z;
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2007 NSImage *image = [data objectAtIndex:index];
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2008 if([image isMemberOfClass:[NSImage class]])
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2009 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2010 thiswidth = [image size].width;
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2011 }
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2012 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2013
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2014 if(thiswidth > width)
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2015 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2016 width = thiswidth;
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2017 }
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2018 }
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2019 /* If the image is missing default the optimized width to 16. */
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2020 if(!width && [[types objectAtIndex:z] intValue] & DW_CFA_BITMAPORICON)
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2021 {
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2022 width = 16;
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2023 }
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2024 }
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2025 if(width)
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2026 cwidth += width;
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2027 }
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2028 }
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2029 cwidth += 16;
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2030 cheight += 16;
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2031 return NSMakeSize(cwidth, cheight);
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
2032 }
856
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2033 -(void)optimize
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2034 {
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2035 if(tvcols)
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2036 {
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2037 int z;
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2038 int colcount = (int)[tvcols count];
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2039 int rowcount = (int)[self numberOfRowsInTableView:self];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2040
856
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2041 for(z=0;z<colcount;z++)
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2042 {
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2043 NSTableColumn *column = [tvcols objectAtIndex:z];
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2044 if([column resizingMask] != NSTableColumnNoResizing)
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2045 {
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2046 if(rowcount > 0)
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2047 {
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2048 int x;
1135
6828a01ecf3c Include the header column text width during container optimize on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1134
diff changeset
2049 NSCell *colcell = [column headerCell];
6828a01ecf3c Include the header column text width during container optimize on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1134
diff changeset
2050 int width = [colcell cellSize].width;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2051
856
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2052 for(x=0;x<rowcount;x++)
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2053 {
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2054 NSCell *cell = [self preparedCellAtColumn:z row:x];
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2055 int thiswidth = [cell cellSize].width;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2056
866
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2057 /* Check the image inside the cell to get its width */
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2058 if([cell isMemberOfClass:[NSImageCell class]])
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2059 {
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2060 int index = (int)(x * [tvcols count]) + z;
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2061 NSImage *image = [data objectAtIndex:index];
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2062 if([image isMemberOfClass:[NSImage class]])
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2063 {
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2064 thiswidth = [image size].width;
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2065 }
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2066 }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2067
856
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2068 if(thiswidth > width)
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2069 {
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2070 width = thiswidth;
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2071 }
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2072 }
866
ba9d38b8d0bc Added code to check the image size inside the cell during optimize.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 864
diff changeset
2073 /* If the image is missing default the optimized width to 16. */
864
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2074 if(!width && [[types objectAtIndex:z] intValue] & DW_CFA_BITMAPORICON)
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2075 {
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2076 width = 16;
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2077 }
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2078 /* Sanity check... don't set the width to 0 */
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2079 if(width)
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2080 {
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2081 [column setWidth:width];
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
2082 }
856
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2083 }
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2084 else
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2085 {
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2086 [column sizeToFit];
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2087 }
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2088 }
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2089 }
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2090 }
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
2091 }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2092 -(void)setForegroundColor:(NSColor *)input
810
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2093 {
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2094 int z, count = (int)[tvcols count];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2095
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2096 fgcolor = input;
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2097 [fgcolor retain];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2098
810
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2099 for(z=0;z<count;z++)
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2100 {
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2101 NSTableColumn *tableColumn = [tvcols objectAtIndex:z];
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2102 NSTextFieldCell *cell = [tableColumn dataCell];
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2103 [cell setTextColor:fgcolor];
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2104 }
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2105 }
708
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
2106 -(void)doubleClicked:(id)sender
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
2107 {
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
2108 /* Handler for container class */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2109 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 9);
708
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
2110 }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2111 -(void)keyUp:(NSEvent *)theEvent
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2112 {
829
f7b6c88bac47 Implemented Enter/Return triggering the item enter event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 828
diff changeset
2113 if([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2114 {
829
f7b6c88bac47 Implemented Enter/Return triggering the item enter event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 828
diff changeset
2115 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 9);
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2116 }
829
f7b6c88bac47 Implemented Enter/Return triggering the item enter event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 828
diff changeset
2117 [super keyUp:theEvent];
f7b6c88bac47 Implemented Enter/Return triggering the item enter event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 828
diff changeset
2118 }
f7b6c88bac47 Implemented Enter/Return triggering the item enter event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 828
diff changeset
2119
867
139acecd6ca0 Guess I wanted to trap didClickTableColumn instead of mouseDownInHeaderOfTableColumn to avoid spurious events.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 866
diff changeset
2120 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
2121 {
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
2122 NSUInteger index = [tvcols indexOfObject:tableColumn];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2123
803
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
2124 /* Handler for column click class */
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
2125 _event_handler(self, (NSEvent *)index, 17);
803
8555ac1bcbcd Attempt at implementing column click events. Doesn't seem to work yet but needed to commit before switching to laptop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 802
diff changeset
2126 }
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
2127 -(void)selectionChanged:(id)sender
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
2128 {
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
2129 /* Handler for container class */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2130 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 12);
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
2131 /* Handler for listbox class */
1102
cfe7d2b6bc16 Added DW_INT_TO_POINTER/DW_UINT_TO_POINTER/DW_POINTER_TO_INT/DW_POINTER_TO_UINT macros.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1101
diff changeset
2132 _event_handler(self, DW_INT_TO_POINTER((int)[self selectedRow]), 11);
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
2133 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2134 -(NSMenu *)menuForEvent:(NSEvent *)event
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
2135 {
710
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2136 int row;
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2137 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil];
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2138 row = (int)[self rowAtPoint:where];
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2139 _event_handler(self, (NSEvent *)[self getRowTitle:row], 10);
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2140 return nil;
659
756015085da7 Fixes for container signal handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 658
diff changeset
2141 }
1806
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2142 -(void)keyDown:(NSEvent *)theEvent
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2143 {
1809
5efaea897310 Fixed back tab handling for certain controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1808
diff changeset
2144 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
1819
d784b85b632e Change incorrect call to DW_MUTEX_LOCK to DW_MUTEX_UNLOCK in dw_mle_get_size()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1809
diff changeset
2145
1809
5efaea897310 Fixed back tab handling for certain controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1808
diff changeset
2146 if(vk == NSTabCharacter || vk == NSBackTabCharacter)
1806
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2147 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2148 [super keyDown:theEvent];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2149 }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2150 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2151 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
2152 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
2153 @end
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2154
1100
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2155 /* Dive into the tree freeing all desired child nodes */
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2156 void _free_tree_recurse(NSMutableArray *node, NSMutableArray *item)
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2157 {
1100
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2158 if(node && ([node isKindOfClass:[NSArray class]]))
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2159 {
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2160 int count = (int)[node count];
1100
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2161 NSInteger index = -1;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2162 int z;
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
2163
1100
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2164 if(item)
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2165 index = [node indexOfObject:item];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2166
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2167 for(z=0;z<count;z++)
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2168 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2169 NSMutableArray *pnt = [node objectAtIndex:z];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2170 NSMutableArray *children = nil;
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
2171
1100
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2172 if(pnt && [pnt isKindOfClass:[NSArray class]])
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2173 {
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2174 children = (NSMutableArray *)[pnt objectAtIndex:3];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2175 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2176
1100
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2177 if(z == index)
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2178 {
1048
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2179 _free_tree_recurse(children, NULL);
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2180 [node removeObjectAtIndex:z];
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2181 count = (int)[node count];
1100
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2182 index = -1;
1048
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2183 z--;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2184 }
1048
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2185 else if(item == NULL)
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2186 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2187 NSString *oldstr = [pnt objectAtIndex:1];
1048
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2188 [oldstr release];
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2189 _free_tree_recurse(children, item);
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2190 }
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2191 else
70bad8a91370 Fix for dw_tree_item_delete() not working if there are no child nodes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1045
diff changeset
2192 _free_tree_recurse(children, item);
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2193 }
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2194 }
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2195 if(!item)
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2196 {
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2197 [node release];
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2198 }
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2199 }
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2200
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2201 /* Subclass for a Tree type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2202 @interface DWTree : NSOutlineView
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
2203 #ifdef BUILDING_FOR_SNOW_LEOPARD
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
2204 <NSOutlineViewDataSource,NSOutlineViewDelegate>
717
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
2205 #endif
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2206 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2207 void *userdata;
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2208 NSTableColumn *treecol;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2209 NSMutableArray *data;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2210 /* Each data item consists of a linked lists of tree item data.
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2211 * NSImage *, NSString *, Item Data *, NSMutableArray * of Children
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2212 */
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2213 id scrollview;
810
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2214 NSColor *fgcolor;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2215 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2216 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2217 -(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2218 -(int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2219 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2220 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item;
710
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2221 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2222 -(void)addTree:(NSMutableArray *)item and:(NSMutableArray *)parent after:(NSMutableArray *)after;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2223 -(void *)userdata;
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2224 -(void)setUserdata:(void *)input;
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
2225 -(void)treeSelectionChanged:(id)sender;
722
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
2226 -(void)treeItemExpanded:(NSNotification *)notification;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2227 -(NSScrollView *)scrollview;
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2228 -(void)setScrollview:(NSScrollView *)input;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2229 -(void)deleteNode:(NSMutableArray *)item;
810
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2230 -(void)setForegroundColor:(NSColor *)input;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2231 -(void)clear;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2232 @end
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2233
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2234 @implementation DWTree
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2235 -(id)init
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2236 {
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2237 self = [super init];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2238
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2239 if (self)
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2240 {
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2241 treecol = [[NSTableColumn alloc] init];
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
2242 DWImageAndTextCell *browsercell = [[[DWImageAndTextCell alloc] init] autorelease];
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2243 [treecol setDataCell:browsercell];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2244 [self addTableColumn:treecol];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2245 [self setOutlineTableColumn:treecol];
743
4462bc7de1e3 Possible fix for container (and possibly tree) controls picking up combobox events.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 742
diff changeset
2246 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(treeSelectionChanged:) name:NSOutlineViewSelectionDidChangeNotification object:self];
4462bc7de1e3 Possible fix for container (and possibly tree) controls picking up combobox events.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 742
diff changeset
2247 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(treeItemExpanded:) name:NSOutlineViewItemDidExpandNotification object:self];
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2248 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2249 return self;
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2250 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2251 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2252 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2253 if(item)
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2254 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2255 NSMutableArray *array = [item objectAtIndex:3];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2256 return ([array isKindOfClass:[NSNull class]]) ? nil : [array objectAtIndex:index];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2257 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2258 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2259 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2260 return [data objectAtIndex:index];
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2261 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2262 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2263 -(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2264 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2265 return [self outlineView:outlineView numberOfChildrenOfItem:item] != 0;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2266 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2267 -(int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2268 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2269 if(item)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2270 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2271 if([item isKindOfClass:[NSMutableArray class]])
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2272 {
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2273 NSMutableArray *array = [item objectAtIndex:3];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2274 return ([array isKindOfClass:[NSNull class]]) ? 0 : (int)[array count];
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2275 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2276 else
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2277 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2278 return 0;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2279 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2280 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2281 else
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2282 {
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2283 return data ? (int)[data count] : 0;
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2284 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2285 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2286 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2287 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2288 if(item)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2289 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2290 if([item isKindOfClass:[NSMutableArray class]])
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2291 {
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2292 NSMutableArray *this = (NSMutableArray *)item;
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2293 return [this objectAtIndex:1];
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2294 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2295 else
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2296 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2297 return nil;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2298 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2299 }
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2300 return @"List Root";
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2301 }
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2302 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2303 {
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
2304 if([cell isMemberOfClass:[DWImageAndTextCell class]])
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2305 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2306 NSMutableArray *this = (NSMutableArray *)item;
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2307 NSImage *img = [this objectAtIndex:0];
1067
6ca1132a240e Allow tree nodes without icons using the new NSMutableArray tree code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1065
diff changeset
2308 if([img isKindOfClass:[NSImage class]])
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
2309 [(DWImageAndTextCell*)cell setImage:img];
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2310 }
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2311 }
710
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2312 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { return NO; }
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2313 -(void)addTree:(NSMutableArray *)item and:(NSMutableArray *)parent after:(NSMutableArray *)after
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2314 {
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2315 NSMutableArray *children = data;
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2316 if(parent)
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2317 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2318 children = [parent objectAtIndex:3];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2319 if([children isKindOfClass:[NSNull class]])
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2320 {
692
bd909322f40d Added "retain"s to the DWTree/DWContainer/DWListBox classes memory allocation
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 691
diff changeset
2321 children = [[[NSMutableArray alloc] init] retain];
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2322 [parent replaceObjectAtIndex:3 withObject:children];
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2323 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2324 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2325 else
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2326 {
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2327 if(!data)
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2328 {
692
bd909322f40d Added "retain"s to the DWTree/DWContainer/DWListBox classes memory allocation
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 691
diff changeset
2329 children = data = [[[NSMutableArray alloc] init] retain];
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2330 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2331 }
1064
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
2332 if(after)
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
2333 {
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
2334 NSInteger index = [children indexOfObject:after];
1100
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2335 int count = (int)[children count];
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2336 if(index != NSNotFound && (index+1) < count)
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2337 [children insertObject:item atIndex:(index+1)];
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2338 else
13ea7575d9e8 Fixed a problem with dw_tree_item_delete() due to earlier tree data storage changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1099
diff changeset
2339 [children addObject:item];
1064
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
2340 }
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
2341 else
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
2342 {
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
2343 [children addObject:item];
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
2344 }
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2345 }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2346 -(void *)userdata { return userdata; }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2347 -(void)setUserdata:(void *)input { userdata = input; }
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
2348 -(void)treeSelectionChanged:(id)sender
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
2349 {
710
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2350 /* Handler for tree class */
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
2351 id item = [self itemAtRow:[self selectedRow]];
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
2352
713
2c8fc0fd8c11 Don't send tree events with no selected item. Also don't strdup a NULL string.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 712
diff changeset
2353 if(item)
2c8fc0fd8c11 Don't send tree events with no selected item. Also don't strdup a NULL string.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 712
diff changeset
2354 {
2c8fc0fd8c11 Don't send tree events with no selected item. Also don't strdup a NULL string.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 712
diff changeset
2355 _event_handler(self, (void *)item, 12);
2c8fc0fd8c11 Don't send tree events with no selected item. Also don't strdup a NULL string.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 712
diff changeset
2356 }
710
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2357 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2358 -(void)treeItemExpanded:(NSNotification *)notification
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2359 {
722
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
2360 id item = [[notification userInfo ] objectForKey: @"NSObject"];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2361
722
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
2362 if(item)
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
2363 {
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
2364 _event_handler(self, (void *)item, 16);
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
2365 }
5a8d5161651d Implemented tree expand event.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 721
diff changeset
2366 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2367 -(NSMenu *)menuForEvent:(NSEvent *)event
710
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2368 {
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2369 int row;
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2370 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil];
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2371 row = (int)[self rowAtPoint:where];
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2372 id item = [self itemAtRow:row];
1061
d91e09dc3865 Fix for the item data field of the context event always being NULL even for tree items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1051
diff changeset
2373 _event_handler(self, (NSEvent *)item, 10);
710
78460ff977c1 Finishing up tree event/signal handlers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 709
diff changeset
2374 return nil;
709
5a268d5f1cfa Fixes for tree event handling. Still more to come shortly...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 708
diff changeset
2375 }
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2376 -(NSScrollView *)scrollview { return scrollview; }
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2377 -(void)setScrollview:(NSScrollView *)input { scrollview = input; }
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
2378 -(void)deleteNode:(NSMutableArray *)item { _free_tree_recurse(data, item); }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2379 -(void)setForegroundColor:(NSColor *)input
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2380 {
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2381 NSTextFieldCell *cell = [treecol dataCell];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2382 fgcolor = input;
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2383 [fgcolor retain];
810
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2384 [cell setTextColor:fgcolor];
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
2385 }
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2386 -(void)clear { NSMutableArray *toclear = data; data = nil; _free_tree_recurse(toclear, NULL); [self reloadData]; }
1806
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2387 -(void)keyDown:(NSEvent *)theEvent
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2388 {
1809
5efaea897310 Fixed back tab handling for certain controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1808
diff changeset
2389 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
1819
d784b85b632e Change incorrect call to DW_MUTEX_LOCK to DW_MUTEX_UNLOCK in dw_mle_get_size()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1809
diff changeset
2390
1809
5efaea897310 Fixed back tab handling for certain controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1808
diff changeset
2391 if(vk == NSTabCharacter || vk == NSBackTabCharacter)
1806
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2392 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2393 [super keyDown:theEvent];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2394 }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2395 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2396 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2397 -(void)dealloc
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2398 {
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2399 UserData *root = userdata;
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2400 _remove_userdata(&root, NULL, TRUE);
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2401 _free_tree_recurse(data, NULL);
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
2402 [treecol release];
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
2403 dw_signal_disconnect_by_window(self);
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2404 [super dealloc];
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
2405 }
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2406 @end
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
2407
656
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2408 /* Subclass for a Calendar type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2409 @interface DWCalendar : NSDatePicker
655
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2410 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2411 void *userdata;
655
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2412 }
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2413 -(void *)userdata;
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2414 -(void)setUserdata:(void *)input;
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2415 @end
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2416
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2417 @implementation DWCalendar
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2418 -(void *)userdata { return userdata; }
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2419 -(void)setUserdata:(void *)input { userdata = input; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
2420 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
655
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2421 @end
27eb39d2577b Calendar and HTML functions filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 654
diff changeset
2422
656
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2423 /* Subclass for a Combobox type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2424 @interface DWComboBox : NSComboBox
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
2425 #ifdef BUILDING_FOR_SNOW_LEOPARD
717
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
2426 <NSComboBoxDelegate>
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
2427 #endif
656
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2428 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2429 void *userdata;
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2430 id clickDefault;
656
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2431 }
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2432 -(void *)userdata;
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2433 -(void)setUserdata:(void *)input;
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
2434 -(void)comboBoxSelectionDidChange:(NSNotification *)not;
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2435 -(void)setClickDefault:(id)input;
656
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2436 @end
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2437
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2438 @implementation DWComboBox
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2439 -(void *)userdata { return userdata; }
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2440 -(void)setUserdata:(void *)input { userdata = input; }
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
2441 -(void)comboBoxSelectionDidChange:(NSNotification *)not { _event_handler(self, (void *)[self indexOfSelectedItem], 11); }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2442 -(void)setClickDefault:(id)input { clickDefault = input; }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2443 -(void)keyUp:(NSEvent *)theEvent
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2444 {
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2445 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2446 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2447 [[self window] makeFirstResponder:clickDefault];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2448 } else
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2449 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2450 [super keyUp:theEvent];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2451 }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2452 }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
2453 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2454 @end
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2455
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2456 /* Subclass for a stepper component of the spinbutton type */
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2457 /* This is a bad way of doing this... but I can't get the other methods to work */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2458 @interface DWStepper : NSStepper
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2459 {
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2460 id textfield;
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2461 id parent;
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2462 }
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2463 -(void)setTextfield:(id)input;
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2464 -(id)textfield;
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2465 -(void)setParent:(id)input;
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2466 -(id)parent;
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2467 -(void)mouseDown:(NSEvent *)event;
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2468 -(void)mouseUp:(NSEvent *)event;
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2469 @end
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2470
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2471 @implementation DWStepper
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2472 -(void)setTextfield:(id)input { textfield = input; }
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2473 -(id)textfield { return textfield; }
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2474 -(void)setParent:(id)input { parent = input; }
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2475 -(id)parent { return parent; }
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2476 -(void)mouseDown:(NSEvent *)event
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2477 {
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2478 [super mouseDown:event];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2479 if([[NSApp currentEvent] type] == NSLeftMouseUp)
1302
5fbf384780d1 Simplified the DWStepper class a bit on Mac... although it really needs rewriting.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1301
diff changeset
2480 [self mouseUp:event];
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2481 }
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2482 -(void)mouseUp:(NSEvent *)event
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2483 {
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2484 [textfield takeIntValueFrom:self];
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2485 _event_handler(parent, (void *)[self integerValue], 14);
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2486 }
1806
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2487 -(void)keyDown:(NSEvent *)theEvent
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2488 {
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2489 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2490 if(vk == VK_UP || vk == VK_DOWN)
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2491 {
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2492 if(vk == VK_UP)
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2493 [self setIntegerValue:([self integerValue]+[self increment])];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2494 else
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2495 [self setIntegerValue:([self integerValue]-[self increment])];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2496 [self mouseUp:theEvent];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2497 }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2498 else
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2499 {
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2500 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2501 [super keyDown:theEvent];
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2502 }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2503 }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2504 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
eecf0eb609d8 Added keyboard handling for (check/radio/spin)buttons, containers, trees, lists on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1805
diff changeset
2505 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2506 @end
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2507
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2508 /* Subclass for a Spinbutton type */
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2509 @interface DWSpinButton : NSView
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
2510 #ifdef BUILDING_FOR_SNOW_LEOPARD
717
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
2511 <NSTextFieldDelegate>
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
2512 #endif
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2513 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2514 void *userdata;
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2515 NSTextField *textfield;
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2516 DWStepper *stepper;
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2517 id clickDefault;
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2518 }
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2519 -(id)init;
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2520 -(void *)userdata;
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2521 -(void)setUserdata:(void *)input;
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2522 -(NSTextField *)textfield;
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2523 -(NSStepper *)stepper;
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2524 -(void)controlTextDidChange:(NSNotification *)aNotification;
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2525 -(void)setClickDefault:(id)input;
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2526 @end
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2527
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2528 @implementation DWSpinButton
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2529 -(id)init
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2530 {
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2531 self = [super init];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2532
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2533 if(self)
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2534 {
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
2535 textfield = [[[NSTextField alloc] init] autorelease];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2536 [self addSubview:textfield];
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
2537 stepper = [[[DWStepper alloc] init] autorelease];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2538 [self addSubview:stepper];
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2539 [stepper setParent:self];
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2540 [stepper setTextfield:textfield];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2541 [textfield takeIntValueFrom:stepper];
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2542 [textfield setDelegate:self];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2543 }
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2544 return self;
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2545 }
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2546 -(void *)userdata { return userdata; }
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2547 -(void)setUserdata:(void *)input { userdata = input; }
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2548 -(NSTextField *)textfield { return textfield; }
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2549 -(NSStepper *)stepper { return stepper; }
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2550 -(void)controlTextDidChange:(NSNotification *)aNotification
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2551 {
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2552 [stepper takeIntValueFrom:textfield];
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2553 [textfield takeIntValueFrom:stepper];
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
2554 _event_handler(self, (void *)[stepper integerValue], 14);
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
2555 }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2556 -(void)setClickDefault:(id)input { clickDefault = input; }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2557 -(void)keyUp:(NSEvent *)theEvent
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2558 {
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2559 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2560 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2561 [[self window] makeFirstResponder:clickDefault];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2562 }
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2563 else
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2564 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2565 [super keyUp:theEvent];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2566 }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2567 }
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
2568 -(void)performClick:(id)sender { [textfield performClick:sender]; }
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
2569 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
656
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2570 @end
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
2571
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
2572 /* Subclass for a MDI type
684
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2573 * This is just a box for display purposes... but it is a
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2574 * unique class so it can be identified when creating windows.
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2575 */
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2576 @interface DWMDI : DWBox {}
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2577 @end
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2578
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2579 @implementation DWMDI
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2580 @end
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
2581
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2582 /* This function adds a signal handler callback into the linked list.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2583 */
688
b52f1d4a60dd Fixes for timers not working properly. Includes commented out test container code for threadsafety.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 687
diff changeset
2584 void _new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *data)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2585 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2586 SignalHandler *new = malloc(sizeof(SignalHandler));
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
2587
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2588 new->message = message;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2589 new->window = window;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2590 new->id = msgid;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2591 new->signalfunction = signalfunction;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2592 new->data = data;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2593 new->next = NULL;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
2594
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2595 if (!Root)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2596 Root = new;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2597 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2598 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2599 SignalHandler *prev = NULL, *tmp = Root;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2600 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2601 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2602 if(tmp->message == message &&
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2603 tmp->window == window &&
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2604 tmp->id == msgid &&
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2605 tmp->signalfunction == signalfunction)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2606 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2607 tmp->data = data;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2608 free(new);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2609 return;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2610 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2611 prev = tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2612 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2613 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2614 if(prev)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2615 prev->next = new;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2616 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2617 Root = new;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2618 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2619 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2620
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2621 /* Finds the message number for a given signal name */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2622 ULONG _findsigmessage(char *signame)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2623 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2624 int z;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
2625
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2626 for(z=0;z<SIGNALMAX;z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2627 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2628 if(strcasecmp(signame, SignalTranslate[z].name) == 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2629 return SignalTranslate[z].message;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2630 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2631 return 0L;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2632 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2633
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2634 unsigned long _foreground = 0xAAAAAA, _background = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2635
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2636 void _handle_resize_events(Box *thisbox)
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2637 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2638 int z;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2639
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2640 for(z=0;z<thisbox->count;z++)
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2641 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2642 id handle = thisbox->items[z].hwnd;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2643
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2644 if(thisbox->items[z].type == TYPEBOX)
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2645 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2646 Box *tmp = [handle box];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2647
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2648 if(tmp)
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2649 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2650 _handle_resize_events(tmp);
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2651 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2652 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2653 else
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2654 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2655 if([handle isMemberOfClass:[DWRender class]])
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2656 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2657 DWRender *render = (DWRender *)handle;
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2658 NSSize oldsize = [render size];
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2659 NSSize newsize = [render frame].size;
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2660 NSWindow *window = [render window];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2661
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2662 if([window preferredBackingLocation] != NSWindowBackingLocationVideoMemory)
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2663 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2664 [window setPreferredBackingLocation:NSWindowBackingLocationVideoMemory];
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2665 }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2666
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2667 /* Eliminate duplicate configure requests */
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2668 if(oldsize.width != newsize.width || oldsize.height != newsize.height)
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2669 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2670 if(newsize.width > 0 && newsize.height > 0)
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2671 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2672 [render setSize:newsize];
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2673 _event_handler(handle, nil, 1);
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2674 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2675 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2676 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2677 /* Special handling for notebook controls */
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2678 else if([handle isMemberOfClass:[DWNotebook class]])
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2679 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2680 DWNotebook *notebook = (DWNotebook *)handle;
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2681 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem];
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2682 id view = [notepage view];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2683
1805
2bcdc3cfffa7 Make sure the view packed into the notebook on Mac is a DWBox class...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1802
diff changeset
2684 if([view isMemberOfClass:[DWBox class]])
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2685 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2686 Box *box = [view box];
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2687 _handle_resize_events(box);
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2688 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2689 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2690 /* Handle laying out scrollviews... if required space is less
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2691 * than available space, then expand. Otherwise use required space.
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2692 */
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2693 else if([handle isMemberOfClass:[DWScrollBox class]])
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2694 {
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2695 DWScrollBox *scrollbox = (DWScrollBox *)handle;
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2696 DWBox *contentbox = [scrollbox documentView];
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2697 Box *thisbox = [contentbox box];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2698
916
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2699 /* Get the required space for the box */
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2700 _handle_resize_events(thisbox);
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2701 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2702 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2703 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2704 }
44a0f9a2e8f9 Experimental change, pulling the resize event handling out of the resizer code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 915
diff changeset
2705
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2706 /* This function calculates how much space the widgets and boxes require
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2707 * and does expansion as necessary.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2708 */
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2709 static void _resize_box(Box *thisbox, int *depth, int x, int y, int pass)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2710 {
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2711 /* Current item position */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2712 int z, currentx = thisbox->pad, currenty = thisbox->pad;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2713 /* Used x, y and padding maximum values...
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2714 * These will be used to find the widest or
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2715 * tallest items in a box.
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2716 */
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2717 int uymax = 0, uxmax = 0;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2718 int upymax = 0, upxmax = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2719
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2720 /* Reset the box sizes */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2721 thisbox->minwidth = thisbox->minheight = thisbox->usedpadx = thisbox->usedpady = thisbox->pad * 2;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2722
798
1b0a0775ec19 Ok... groupbox calculation fix try #2!
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 797
diff changeset
2723 /* Handle special groupbox case */
1b0a0775ec19 Ok... groupbox calculation fix try #2!
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 797
diff changeset
2724 if(thisbox->grouphwnd)
1b0a0775ec19 Ok... groupbox calculation fix try #2!
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 797
diff changeset
2725 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2726 /* Only calculate the size on the first pass...
1442
02a329b2b0cd Added groupbox perfomance improvement to Windows and OS/2 that was missed when importing from the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1438
diff changeset
2727 * use the cached values on second.
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2728 */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2729 if(pass == 1)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2730 {
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2731 DWGroupBox *groupbox = thisbox->grouphwnd;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2732 NSSize borderSize = [groupbox borderSize];
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2733 NSRect titleRect;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2734
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2735 if(borderSize.width == 0 || borderSize.height == 0)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2736 {
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2737 borderSize = [groupbox initBorder];
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2738 }
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2739 /* Get the title size for a more accurate groupbox padding size */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2740 titleRect = [groupbox titleRect];
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2741
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2742 thisbox->grouppadx = borderSize.width;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2743 thisbox->grouppady = borderSize.height + titleRect.size.height;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2744 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2745
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2746 thisbox->minwidth += thisbox->grouppadx;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2747 thisbox->usedpadx += thisbox->grouppadx;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2748 thisbox->minheight += thisbox->grouppady;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2749 thisbox->usedpady += thisbox->grouppady;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2750 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2751
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2752 /* Count up all the space for all items in the box */
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2753 for(z=0;z<thisbox->count;z++)
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2754 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2755 int itempad, itemwidth, itemheight;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2756
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2757 if(thisbox->items[z].type == TYPEBOX)
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2758 {
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
2759 id box = thisbox->items[z].hwnd;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
2760 Box *tmp = [box box];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2761
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2762 if(tmp)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2763 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2764 /* On the first pass calculate the box contents */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2765 if(pass == 1)
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2766 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2767 (*depth)++;
1449
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2768
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2769 /* Save the newly calculated values on the box */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2770 _resize_box(tmp, depth, x, y, pass);
1449
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2771
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2772 /* Duplicate the values in the item list for use below */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2773 thisbox->items[z].width = tmp->minwidth;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2774 thisbox->items[z].height = tmp->minheight;
1449
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2775
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2776 /* If the box has no contents but is expandable... default the size to 1 */
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2777 if(!thisbox->items[z].width && thisbox->items[z].hsize)
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2778 thisbox->items[z].width = 1;
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2779 if(!thisbox->items[z].height && thisbox->items[z].vsize)
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2780 thisbox->items[z].height = 1;
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2781
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2782 (*depth)--;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2783 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2784 }
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2785 }
1449
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
2786
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2787 /* Precalculate these values, since they will
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2788 * be used used repeatedly in the next section.
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2789 */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2790 itempad = thisbox->items[z].pad * 2;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2791 itemwidth = thisbox->items[z].width + itempad;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2792 itemheight = thisbox->items[z].height + itempad;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2793
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2794 /* Calculate the totals and maximums */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2795 if(thisbox->type == DW_VERT)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2796 {
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2797 if(itemwidth > uxmax)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2798 uxmax = itemwidth;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2799
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2800 if(thisbox->items[z].hsize != SIZEEXPAND)
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2801 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2802 if(itemwidth > upxmax)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2803 upxmax = itemwidth;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2804 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2805 else
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2806 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2807 if(itempad > upxmax)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2808 upxmax = itempad;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2809 }
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2810 thisbox->minheight += itemheight;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2811 if(thisbox->items[z].vsize != SIZEEXPAND)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2812 thisbox->usedpady += itemheight;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2813 else
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2814 thisbox->usedpady += itempad;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2815 }
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2816 else
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2817 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2818 if(itemheight > uymax)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2819 uymax = itemheight;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2820 if(thisbox->items[z].vsize != SIZEEXPAND)
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2821 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2822 if(itemheight > upymax)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2823 upymax = itemheight;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2824 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2825 else
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2826 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2827 if(itempad > upymax)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2828 upymax = itempad;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2829 }
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2830 thisbox->minwidth += itemwidth;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2831 if(thisbox->items[z].hsize != SIZEEXPAND)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2832 thisbox->usedpadx += itemwidth;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2833 else
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2834 thisbox->usedpadx += itempad;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2835 }
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2836 }
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2837
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2838 /* Add the maximums which were calculated in the previous loop */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2839 thisbox->minwidth += uxmax;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2840 thisbox->minheight += uymax;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2841 thisbox->usedpadx += upxmax;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2842 thisbox->usedpady += upymax;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2843
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2844 /* The second pass is for actual placement. */
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2845 if(pass > 1)
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2846 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2847 for(z=0;z<(thisbox->count);z++)
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2848 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2849 int height = thisbox->items[z].height;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2850 int width = thisbox->items[z].width;
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2851 int itempad = thisbox->items[z].pad * 2;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2852 int thispad = thisbox->pad * 2;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2853
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2854 /* Calculate the new sizes */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2855 if(thisbox->items[z].hsize == SIZEEXPAND)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2856 {
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2857 if(thisbox->type == DW_HORZ)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2858 {
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2859 int expandablex = thisbox->minwidth - thisbox->usedpadx;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2860
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2861 if(expandablex)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2862 width = (int)(((float)width / (float)expandablex) * (float)(x - thisbox->usedpadx));
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2863 }
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2864 else
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2865 width = x - (itempad + thispad + thisbox->grouppadx);
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2866 }
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2867 if(thisbox->items[z].vsize == SIZEEXPAND)
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
2868 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2869 if(thisbox->type == DW_VERT)
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2870 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2871 int expandabley = thisbox->minheight - thisbox->usedpady;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2872
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2873 if(expandabley)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2874 height = (int)(((float)height / (float)expandabley) * (float)(y - thisbox->usedpady));
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2875 }
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2876 else
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2877 height = y - (itempad + thispad + thisbox->grouppady);
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2878 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2879
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2880 /* If the calculated size is valid... */
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2881 if(height > 0 && width > 0)
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2882 {
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2883 int pad = thisbox->items[z].pad;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2884 NSView *handle = thisbox->items[z].hwnd;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2885 NSPoint point;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2886 NSSize size;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2887
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2888 point.x = currentx + pad;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2889 point.y = currenty + pad;
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2890 size.width = width;
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2891 size.height = height;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2892 [handle setFrameOrigin:point];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2893 [handle setFrameSize:size];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2894
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2895 /* After placing a box... place its components */
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2896 if(thisbox->items[z].type == TYPEBOX)
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
2897 {
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2898 id box = thisbox->items[z].hwnd;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2899 Box *tmp = [box box];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2900
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2901 if(tmp)
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2902 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2903 (*depth)++;
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2904 _resize_box(tmp, depth, width, height, pass);
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2905 (*depth)--;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2906 }
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
2907 }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2908
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2909 /* Special handling for notebook controls */
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2910 if([handle isMemberOfClass:[DWNotebook class]])
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
2911 {
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2912 DWNotebook *notebook = (DWNotebook *)handle;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2913 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2914 id view = [notepage view];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2915
1805
2bcdc3cfffa7 Make sure the view packed into the notebook on Mac is a DWBox class...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1802
diff changeset
2916 if([view isMemberOfClass:[DWBox class]])
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2917 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2918 Box *box = [view box];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2919 NSSize size = [view frame].size;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2920 _do_resize(box, size.width, size.height);
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2921 _handle_resize_events(box);
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2922 }
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
2923 }
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2924 /* Handle laying out scrollviews... if required space is less
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2925 * than available space, then expand. Otherwise use required space.
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2926 */
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2927 else if([handle isMemberOfClass:[DWScrollBox class]])
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2928 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2929 int depth = 0;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2930 DWScrollBox *scrollbox = (DWScrollBox *)handle;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2931 DWBox *contentbox = [scrollbox documentView];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2932 Box *thisbox = [contentbox box];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2933 NSSize contentsize = [scrollbox contentSize];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2934
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2935 /* Get the required space for the box */
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2936 _resize_box(thisbox, &depth, x, y, 1);
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2937
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2938 if(contentsize.width < thisbox->minwidth)
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2939 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2940 contentsize.width = thisbox->minwidth;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2941 }
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2942 if(contentsize.height < thisbox->minheight)
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2943 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2944 contentsize.height = thisbox->minheight;
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2945 }
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2946 [contentbox setFrameSize:contentsize];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2947
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2948 /* Layout the content of the scrollbox */
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2949 _do_resize(thisbox, contentsize.width, contentsize.height);
929
d7e88ac1647c Removed some code that had been used for debugging the layout code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 928
diff changeset
2950 _handle_resize_events(thisbox);
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2951 }
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2952 /* Special handling for spinbutton controls */
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2953 else if([handle isMemberOfClass:[DWSpinButton class]])
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2954 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2955 DWSpinButton *spinbutton = (DWSpinButton *)handle;
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2956 NSTextField *textfield = [spinbutton textfield];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2957 NSStepper *stepper = [spinbutton stepper];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2958 [textfield setFrameOrigin:NSMakePoint(0,0)];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2959 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2960 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2961 [stepper setFrameSize:NSMakeSize(20,size.height)];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2962 }
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
2963 else if([handle isMemberOfClass:[DWSplitBar class]])
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2964 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2965 DWSplitBar *split = (DWSplitBar *)handle;
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
2966 DWWindow *window = (DWWindow *)[split window];
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2967 float percent = [split percent];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
2968
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
2969 if(percent > 0 && size.width > 20 && size.height > 20)
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2970 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2971 dw_splitbar_set(handle, percent);
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2972 [split setPercent:0];
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2973 }
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
2974 else if([window redraw])
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
2975 {
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
2976 [split splitViewDidResizeSubviews:nil];
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
2977 }
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2978 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2979
1438
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
2980 /* Advance the current position in the box */
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2981 if(thisbox->type == DW_HORZ)
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2982 currentx += width + (pad * 2);
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2983 if(thisbox->type == DW_VERT)
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2984 currenty += height + (pad * 2);
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
2985 }
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2986 }
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2987 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2988 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2989
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2990 static void _do_resize(Box *thisbox, int x, int y)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2991 {
943
675c12b1b90e Changed check from x and y not being zero to x and y being greater than zero since it seems values can be negative on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 942
diff changeset
2992 if(x > 0 && y > 0)
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2993 {
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2994 if(thisbox)
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2995 {
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2996 int depth = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
2997
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
2998 /* Calculate space requirements */
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
2999 _resize_box(thisbox, &depth, x, y, 1);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3000
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
3001 /* Finally place all the boxes and controls */
1437
a50e8b486a1a Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1435
diff changeset
3002 _resize_box(thisbox, &depth, x, y, 2);
928
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
3003 }
43a5b3c78c41 Two fixes... the first is on the fly calculation of groupbox border size. This also fixes some initial window issues...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 927
diff changeset
3004 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3005 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3006
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
3007 NSMenu *_generate_main_menu()
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
3008 {
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
3009 NSString *applicationName = nil;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3010
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
3011 /* This only works on 10.6 so we have a backup method */
719
d5e49ef8f541 Updated the #if for Snow Leopard/Leopard builds to handle them not being defined properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 718
diff changeset
3012 #ifdef BUILDING_FOR_SNOW_LEOPARD
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
3013 applicationName = [[NSRunningApplication currentApplication] localizedName];
717
17923b931393 Fixes for building for MacOS 10.5 and PPC
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 715
diff changeset
3014 #endif
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
3015 if(applicationName == nil)
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
3016 {
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
3017 applicationName = [[NSProcessInfo processInfo] processName];
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
3018 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3019
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3020 /* Create the main menu */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3021 NSMenu * mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3022
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3023 NSMenuItem * mitem = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3024 NSMenu * menu = [[[NSMenu alloc] initWithTitle:@"Apple"] autorelease];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3025
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3026 [DWApp performSelector:@selector(setAppleMenu:) withObject:menu];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3027
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3028 /* Setup the Application menu */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3029 NSMenuItem * item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"About", nil), applicationName]
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3030 action:@selector(orderFrontStandardAboutPanel:)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3031 keyEquivalent:@""];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3032 [item setTarget:DWApp];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3033
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3034 [menu addItem:[NSMenuItem separatorItem]];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3035
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3036 item = [menu addItemWithTitle:NSLocalizedString(@"Services", nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3037 action:NULL
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3038 keyEquivalent:@""];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3039 NSMenu * servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3040 [menu setSubmenu:servicesMenu forItem:item];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3041 [DWApp setServicesMenu:servicesMenu];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3042
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3043 [menu addItem:[NSMenuItem separatorItem]];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3044
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3045 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Hide", nil), applicationName]
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3046 action:@selector(hide:)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3047 keyEquivalent:@"h"];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3048 [item setTarget:DWApp];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3049
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3050 item = [menu addItemWithTitle:NSLocalizedString(@"Hide Others", nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3051 action:@selector(hideOtherApplications:)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3052 keyEquivalent:@"h"];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3053 [item setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3054 [item setTarget:DWApp];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3055
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3056 item = [menu addItemWithTitle:NSLocalizedString(@"Show All", nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3057 action:@selector(unhideAllApplications:)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3058 keyEquivalent:@""];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3059 [item setTarget:DWApp];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3060
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3061 [menu addItem:[NSMenuItem separatorItem]];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3062
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3063 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Quit", nil), applicationName]
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3064 action:@selector(terminate:)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3065 keyEquivalent:@"q"];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3066 [item setTarget:DWApp];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3067
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3068 [mainMenu setSubmenu:menu forItem:mitem];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3069
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3070 return mainMenu;
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
3071 }
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
3072
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
3073 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3074 * Runs a message loop for Dynamic Windows.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3075 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3076 void API dw_main(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3077 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
3078 dw_mutex_lock(DWRunMutex);
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
3079 DWThread = dw_thread_id();
1449
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
3080 /* Make sure any queued redraws are handled */
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
3081 _dw_redraw(0, FALSE);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3082 [DWApp run];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
3083 DWThread = (DWTID)-1;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
3084 dw_mutex_unlock(DWRunMutex);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3085 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3086
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3087 /*
1528
5facb5380944 Added dw_main_quit() function for exiting the dw_main() loop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1527
diff changeset
3088 * Causes running dw_main() to return.
5facb5380944 Added dw_main_quit() function for exiting the dw_main() loop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1527
diff changeset
3089 */
5facb5380944 Added dw_main_quit() function for exiting the dw_main() loop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1527
diff changeset
3090 void API dw_main_quit(void)
5facb5380944 Added dw_main_quit() function for exiting the dw_main() loop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1527
diff changeset
3091 {
1529
92bed442620a Didn't notice that [NSApplication stop] took a sender parameter on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1528
diff changeset
3092 [DWApp stop:nil];
1558
9c5d3ac5bec5 Attempted fix on Mac for 10.5 menu event delay issue.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1557
diff changeset
3093 _dw_wakeup_app();
1528
5facb5380944 Added dw_main_quit() function for exiting the dw_main() loop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1527
diff changeset
3094 }
5facb5380944 Added dw_main_quit() function for exiting the dw_main() loop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1527
diff changeset
3095
5facb5380944 Added dw_main_quit() function for exiting the dw_main() loop.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1527
diff changeset
3096 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3097 * Runs a message loop for Dynamic Windows, for a period of milliseconds.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3098 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3099 * milliseconds: Number of milliseconds to run the loop for.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3100 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3101 void API dw_main_sleep(int milliseconds)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3102 {
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3103 DWTID curr = pthread_self();
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3104
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3105 if(DWThread == (DWTID)-1 || DWThread == curr)
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3106 {
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3107 DWTID orig = DWThread;
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3108 NSDate *until = [NSDate dateWithTimeIntervalSinceNow:(milliseconds/1000.0)];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3109
695
3b17111499bf Minor updates to the last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 694
diff changeset
3110 if(orig == (DWTID)-1)
3b17111499bf Minor updates to the last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 694
diff changeset
3111 {
728
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3112 dw_mutex_lock(DWRunMutex);
695
3b17111499bf Minor updates to the last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 694
diff changeset
3113 DWThread = curr;
3b17111499bf Minor updates to the last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 694
diff changeset
3114 }
1449
632346743f46 Fixed dw_window_redraw() on Windows not recalculating notebook page contents if the notebook size didn't change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1446
diff changeset
3115 /* Process any pending events */
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3116 while(_dw_main_iteration(until))
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3117 {
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3118 /* Just loop */
695
3b17111499bf Minor updates to the last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 694
diff changeset
3119 }
3b17111499bf Minor updates to the last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 694
diff changeset
3120 if(orig == (DWTID)-1)
3b17111499bf Minor updates to the last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 694
diff changeset
3121 {
3b17111499bf Minor updates to the last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 694
diff changeset
3122 DWThread = orig;
728
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3123 dw_mutex_unlock(DWRunMutex);
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3124 }
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3125 }
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3126 else
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3127 {
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3128 usleep(milliseconds * 1000);
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3129 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3130 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3131
700
7953f0471e4d Some cleanups for the run loop iteration and thread system.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 699
diff changeset
3132 /* Internal version that doesn't lock the run mutex */
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3133 int _dw_main_iteration(NSDate *date)
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3134 {
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3135 NSEvent *event = [DWApp nextEventMatchingMask:NSAnyEventMask
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3136 untilDate:date
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3137 inMode:NSDefaultRunLoopMode
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3138 dequeue:YES];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3139 if(event)
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3140 {
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3141 [DWApp sendEvent:event];
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3142 [DWApp updateWindows];
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3143 return 1;
694
130ca42c4ae3 Reimplementation of dw_main_iteration and dw_main_sleep that actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 693
diff changeset
3144 }
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
3145 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3146 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3147
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3148 /*
700
7953f0471e4d Some cleanups for the run loop iteration and thread system.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 699
diff changeset
3149 * Processes a single message iteration and returns.
7953f0471e4d Some cleanups for the run loop iteration and thread system.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 699
diff changeset
3150 */
7953f0471e4d Some cleanups for the run loop iteration and thread system.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 699
diff changeset
3151 void API dw_main_iteration(void)
7953f0471e4d Some cleanups for the run loop iteration and thread system.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 699
diff changeset
3152 {
728
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3153 DWTID curr = pthread_self();
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3154
728
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3155 if(DWThread == (DWTID)-1)
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3156 {
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3157 dw_mutex_lock(DWRunMutex);
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3158 DWThread = curr;
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3159 _dw_main_iteration([NSDate distantPast]);
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3160 DWThread = (DWTID)-1;
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3161 dw_mutex_unlock(DWRunMutex);
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3162 }
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3163 else if(DWThread == curr)
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3164 {
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3165 _dw_main_iteration([NSDate distantPast]);
55f22b39ab57 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 727
diff changeset
3166 }
700
7953f0471e4d Some cleanups for the run loop iteration and thread system.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 699
diff changeset
3167 }
7953f0471e4d Some cleanups for the run loop iteration and thread system.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 699
diff changeset
3168
7953f0471e4d Some cleanups for the run loop iteration and thread system.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 699
diff changeset
3169 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3170 * Cleanly terminates a DW session, should be signal handler safe.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3171 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3172 * exitcode: Exit code reported to the operating system.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3173 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3174 void API dw_exit(int exitcode)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3175 {
1559
bc3a11fe9a46 Don't use _dw_pool_drain() in dw_exit() on Mac... that drains and recreates the pool.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1558
diff changeset
3176 #if !defined(GARBAGE_COLLECT)
bc3a11fe9a46 Don't use _dw_pool_drain() in dw_exit() on Mac... that drains and recreates the pool.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1558
diff changeset
3177 pool = pthread_getspecific(_dw_pool_key);
bc3a11fe9a46 Don't use _dw_pool_drain() in dw_exit() on Mac... that drains and recreates the pool.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1558
diff changeset
3178 [pool drain];
bc3a11fe9a46 Don't use _dw_pool_drain() in dw_exit() on Mac... that drains and recreates the pool.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1558
diff changeset
3179 #endif
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3180 exit(exitcode);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3181 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3182
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3183 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3184 * Free's memory allocated by dynamic windows.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3185 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3186 * ptr: Pointer to dynamic windows allocated
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3187 * memory to be free()'d.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3188 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3189 void API dw_free(void *ptr)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3190 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3191 free(ptr);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3192 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3193
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3194 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3195 * Returns a pointer to a static buffer which containes the
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3196 * current user directory. Or the root directory (C:\ on
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3197 * OS/2 and Windows).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3198 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3199 char *dw_user_dir(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3200 {
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3201 static char _user_dir[PATH_MAX+1] = { 0 };
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3202
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3203 if(!_user_dir[0])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3204 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3205 char *home = getenv("HOME");
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3206
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3207 if(home)
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3208 strncpy(_user_dir, home, PATH_MAX);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3209 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3210 strcpy(_user_dir, "/");
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3211 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3212 return _user_dir;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3213 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3214
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3215 /*
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3216 * Returns a pointer to a static buffer which containes the
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3217 * private application data directory.
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3218 */
1384
156e32814c83 Cleanup of the previous commits and added Unix support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1383
diff changeset
3219 char * API dw_app_dir(void)
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3220 {
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3221 return _dw_bundle_path;
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3222 }
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3223
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
3224 /*
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3225 * Displays a debug message on the console...
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3226 * Parameters:
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3227 * format: printf style format string.
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3228 * ...: Additional variables for use in the format.
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3229 */
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3230 void API dw_debug(char *format, ...)
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3231 {
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3232 va_list args;
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3233 char outbuf[1025] = {0};
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3234
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3235 va_start(args, format);
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3236 vsnprintf(outbuf, 1024, format, args);
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3237 va_end(args);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3238
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3239 NSLog(@"%s", outbuf);
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3240 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3241
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3242 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3243 * Displays a Message Box with given text and title..
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3244 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3245 * title: The title of the message box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3246 * flags: flags to indicate buttons and icon
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3247 * format: printf style format string.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3248 * ...: Additional variables for use in the format.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3249 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3250 int API dw_messagebox(char *title, int flags, char *format, ...)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3251 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3252 int iResponse;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3253 NSString *button1 = @"OK";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3254 NSString *button2 = nil;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3255 NSString *button3 = nil;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3256 va_list args;
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3257 char outbuf[1025] = {0};
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3258
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3259 va_start(args, format);
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
3260 vsnprintf(outbuf, 1024, format, args);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3261 va_end(args);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3262
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3263 if(flags & DW_MB_OKCANCEL)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3264 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3265 button2 = @"Cancel";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3266 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3267 else if(flags & DW_MB_YESNO)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3268 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3269 button1 = @"Yes";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3270 button2 = @"No";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3271 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3272 else if(flags & DW_MB_YESNOCANCEL)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3273 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3274 button1 = @"Yes";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3275 button2 = @"No";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3276 button3 = @"Cancel";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3277 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3278
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3279 if(flags & DW_MB_ERROR)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3280 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3281 iResponse = (int)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3282 NSRunCriticalAlertPanel([ NSString stringWithUTF8String:title ],
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3283 [ NSString stringWithUTF8String:outbuf ],
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
3284 button1, button2, button3);
936
4be0c9f963f8 Implement informational messagebox style on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 935
diff changeset
3285 }
4be0c9f963f8 Implement informational messagebox style on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 935
diff changeset
3286 else if(flags & DW_MB_INFORMATION)
4be0c9f963f8 Implement informational messagebox style on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 935
diff changeset
3287 {
4be0c9f963f8 Implement informational messagebox style on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 935
diff changeset
3288 iResponse = (int)
4be0c9f963f8 Implement informational messagebox style on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 935
diff changeset
3289 NSRunInformationalAlertPanel([ NSString stringWithUTF8String:title ],
4be0c9f963f8 Implement informational messagebox style on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 935
diff changeset
3290 [ NSString stringWithUTF8String:outbuf ],
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
3291 button1, button2, button3);
936
4be0c9f963f8 Implement informational messagebox style on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 935
diff changeset
3292 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3293 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3294 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3295 iResponse = (int)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3296 NSRunAlertPanel([ NSString stringWithUTF8String:title ],
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3297 [ NSString stringWithUTF8String:outbuf ],
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3298 button1, button2, button3);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3299 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3300
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3301 switch(iResponse)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3302 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3303 case NSAlertDefaultReturn: /* user pressed OK */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3304 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3305 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3306 return DW_MB_RETURN_YES;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3307 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3308 return DW_MB_RETURN_OK;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3309 case NSAlertAlternateReturn: /* user pressed Cancel */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3310 if(flags & DW_MB_OKCANCEL)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3311 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3312 return DW_MB_RETURN_CANCEL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3313 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3314 return DW_MB_RETURN_NO;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3315 case NSAlertOtherReturn: /* user pressed the third button */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3316 return DW_MB_RETURN_CANCEL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3317 case NSAlertErrorReturn: /* an error occurred */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3318 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3319 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3320 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3321 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3322
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3323 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3324 * Opens a file dialog and queries user selection.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3325 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3326 * title: Title bar text for dialog.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3327 * defpath: The default path of the open dialog.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3328 * ext: Default file extention.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3329 * flags: DW_FILE_OPEN or DW_FILE_SAVE.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3330 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3331 * NULL on error. A malloced buffer containing
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3332 * the file path on success.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3333 *
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3334 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3335 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3336 {
1298
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3337 char temp[PATH_MAX+1];
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3338 char *file = NULL, *path = NULL;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3339 DW_LOCAL_POOL_IN;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3340
1301
7527fb644bc0 Only use default directory and filename options for Mac 10.6 and higher.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1298
diff changeset
3341 /* Figure out path information...
7527fb644bc0 Only use default directory and filename options for Mac 10.6 and higher.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1298
diff changeset
3342 * These functions are only support in Snow Leopard and later...
7527fb644bc0 Only use default directory and filename options for Mac 10.6 and higher.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1298
diff changeset
3343 */
1704
873304f581be Fix Unicode issues with the directory browser on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1679
diff changeset
3344 if(defpath && *defpath && DWOSMinor > 5)
1298
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3345 {
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3346 struct stat buf;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3347
1298
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3348 /* Get an absolute path */
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3349 if(!realpath(defpath, temp))
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3350 strcpy(temp, defpath);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3351
1298
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3352 /* Check if the defpath exists */
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3353 if(stat(temp, &buf) == 0)
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3354 {
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3355 /* Can be a directory or file */
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3356 if(buf.st_mode & S_IFDIR)
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3357 path = temp;
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3358 else
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3359 file = temp;
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3360 }
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3361 /* If it wasn't a directory... check if there is a path */
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3362 if(!path && strchr(temp, '/'))
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3363 {
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3364 unsigned long x = strlen(temp) - 1;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3365
1298
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3366 /* Trim off the filename */
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3367 while(x > 0 && temp[x] != '/')
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3368 {
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3369 x--;
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3370 }
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3371 if(temp[x] == '/')
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3372 {
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3373 temp[x] = 0;
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3374 /* Check to make sure the trimmed piece is a directory */
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3375 if(stat(temp, &buf) == 0)
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3376 {
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3377 if(buf.st_mode & S_IFDIR)
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3378 {
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3379 /* We now have it split */
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3380 path = temp;
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3381 file = &temp[x+1];
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3382 }
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3383 }
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3384 }
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3385 }
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3386 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3387
825
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3388 if(flags == DW_FILE_OPEN || flags == DW_DIRECTORY_OPEN)
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3389 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3390 /* Create the File Open Dialog class. */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3391 NSOpenPanel* openDlg = [NSOpenPanel openPanel];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3392
1298
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3393 if(path)
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3394 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3395 SEL ssdu = NSSelectorFromString(@"setDirectoryURL");
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3396
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3397 if([openDlg respondsToSelector:ssdu])
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3398 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3399 IMP isdu = [openDlg methodForSelector:ssdu];
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3400 isdu(openDlg, ssdu, [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]);
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3401 }
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3402 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3403
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3404 /* Enable the selection of files in the dialog. */
825
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3405 if(flags == DW_FILE_OPEN)
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3406 {
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3407 [openDlg setCanChooseFiles:YES];
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3408 [openDlg setCanChooseDirectories:NO];
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3409 }
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3410 else
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3411 {
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3412 [openDlg setCanChooseFiles:NO];
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3413 [openDlg setCanChooseDirectories:YES];
8a2e3138e1e4 Implemented DW_DIRECTORY_OPEN on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 821
diff changeset
3414 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3415
1296
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3416 /* Handle file types */
1704
873304f581be Fix Unicode issues with the directory browser on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1679
diff changeset
3417 if(ext && *ext)
1296
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3418 {
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
3419 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease];
1296
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3420 [openDlg setAllowedFileTypes:fileTypes];
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3421 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3422
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3423 /* Disable multiple selection */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3424 [openDlg setAllowsMultipleSelection:NO];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3425
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3426 /* Display the dialog. If the OK button was pressed,
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3427 * process the files.
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3428 */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3429 if([openDlg runModal] == NSOKButton)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3430 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3431 /* Get an array containing the full filenames of all
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3432 * files and directories selected.
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3433 */
1296
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3434 NSArray *files = [openDlg URLs];
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3435 NSString *fileName = [[files objectAtIndex:0] path];
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3436 if(fileName)
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3437 {
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3438 char *ret = strdup([ fileName UTF8String ]);
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3439 DW_LOCAL_POOL_OUT;
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3440 return ret;
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3441 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3442 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3443 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3444 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3445 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3446 /* Create the File Save Dialog class. */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3447 NSSavePanel* saveDlg = [NSSavePanel savePanel];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3448
1298
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3449 if(path)
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3450 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3451 SEL ssdu = NSSelectorFromString(@"setDirectoryURL");
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3452
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3453 if([saveDlg respondsToSelector:ssdu])
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3454 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3455 IMP isdu = [saveDlg methodForSelector:ssdu];
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3456 isdu(saveDlg, ssdu, [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]);
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3457 }
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3458 }
1298
79db0563c7c2 Code to split the file and path apart on Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1296
diff changeset
3459 if(file)
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3460 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3461 SEL ssnfsv = NSSelectorFromString(@"setNameFieldStringValue");
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3462
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3463 if([saveDlg respondsToSelector:ssnfsv])
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3464 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3465 IMP isnfsv = [saveDlg methodForSelector:ssnfsv];
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3466 isnfsv(saveDlg, ssnfsv, [NSString stringWithUTF8String:file]);
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3467 }
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3468 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3469
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3470 /* Enable the creation of directories in the dialog. */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3471 [saveDlg setCanCreateDirectories:YES];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3472
1296
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3473 /* Handle file types */
1704
873304f581be Fix Unicode issues with the directory browser on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1679
diff changeset
3474 if(ext && *ext)
1296
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3475 {
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
3476 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease];
1296
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3477 [saveDlg setAllowedFileTypes:fileTypes];
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3478 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3479
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3480 /* Display the dialog. If the OK button was pressed,
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3481 * process the files.
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3482 */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3483 if([saveDlg runModal] == NSFileHandlingPanelOKButton)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3484 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3485 /* Get an array containing the full filenames of all
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3486 * files and directories selected.
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3487 */
1296
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3488 NSString* fileName = [[saveDlg URL] path];
40d62db77c90 Added some defpath support and extension support to the Mac dw_file_browse().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1291
diff changeset
3489 if(fileName)
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3490 {
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3491 char *ret = strdup([ fileName UTF8String ]);
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3492 DW_LOCAL_POOL_OUT;
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3493 return ret;
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3494 }
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3495 }
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3496 }
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
3497 DW_LOCAL_POOL_OUT;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3498 return NULL;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3499 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3500
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3501 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3502 * Gets the contents of the default clipboard as text.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3503 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3504 * None.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3505 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3506 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3507 * be converted to text.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3508 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3509 char *dw_clipboard_get_text()
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3510 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3511 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3512 NSString *str = [pasteboard stringForType:NSStringPboardType];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3513 if(str != nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3514 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3515 return strdup([ str UTF8String ]);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3516 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3517 return NULL;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3518 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3519
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3520 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3521 * Sets the contents of the default clipboard to the supplied text.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3522 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3523 * Text.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3524 */
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
3525 void dw_clipboard_set_text( char *str, int len)
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
3526 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3527 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3528 SEL scc = NSSelectorFromString(@"clearContents");
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3529
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3530 if([pasteboard respondsToSelector:scc])
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3531 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3532 IMP icc = [pasteboard methodForSelector:scc];
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
3533 icc(pasteboard, scc);
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
3534 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3535
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3536 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3537 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3538
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3539
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3540 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3541 * Allocates and initializes a dialog struct.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3542 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3543 * data: User defined data to be passed to functions.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3544 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3545 DWDialog * API dw_dialog_new(void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3546 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3547 DWDialog *tmp = malloc(sizeof(DWDialog));
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3548
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3549 if(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3550 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3551 tmp->eve = dw_event_new();
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3552 dw_event_reset(tmp->eve);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3553 tmp->data = data;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3554 tmp->done = FALSE;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3555 tmp->result = NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3556 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3557 return tmp;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3558 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3559
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3560 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3561 * Accepts a dialog struct and returns the given data to the
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3562 * initial called of dw_dialog_wait().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3563 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3564 * dialog: Pointer to a dialog struct aquired by dw_dialog_new).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3565 * result: Data to be returned by dw_dialog_wait().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3566 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3567 int API dw_dialog_dismiss(DWDialog *dialog, void *result)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3568 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3569 dialog->result = result;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3570 dw_event_post(dialog->eve);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3571 dialog->done = TRUE;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3572 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3573 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3574
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3575 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3576 * Accepts a dialog struct waits for dw_dialog_dismiss() to be
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3577 * called by a signal handler with the given dialog struct.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3578 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3579 * dialog: Pointer to a dialog struct aquired by dw_dialog_new).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3580 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3581 void * API dw_dialog_wait(DWDialog *dialog)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3582 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3583 void *tmp;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
3584
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3585 while(!dialog->done)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3586 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3587 _dw_main_iteration([NSDate dateWithTimeIntervalSinceNow:0.01]);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3588 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3589 dw_event_close(&dialog->eve);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3590 tmp = dialog->result;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3591 free(dialog);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3592 return tmp;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3593 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3594
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3595 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3596 * Create a new Box to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3597 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3598 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3599 * pad: Number of pixels to pad around the box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3600 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3601 HWND API dw_box_new(int type, int pad)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3602 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
3603 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
3604 DW_MUTEX_LOCK;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3605 DWBox *view = [[DWBox alloc] init];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3606 Box *newbox = [view box];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3607 memset(newbox, 0, sizeof(Box));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3608 newbox->pad = pad;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3609 newbox->type = type;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
3610 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
3611 return view;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3612 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3613
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3614 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3615 * Create a new Group Box to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3616 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3617 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3618 * pad: Number of pixels to pad around the box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3619 * title: Text to be displayined in the group outline.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3620 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3621 HWND API dw_groupbox_new(int type, int pad, char *title)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3622 {
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
3623 NSBox *groupbox = [[DWGroupBox alloc] init];
796
3a3fae1f31bd Initial groupbox padding calculation fix. This may still need more work... very simple version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 795
diff changeset
3624 DWBox *thisbox = dw_box_new(type, pad);
3a3fae1f31bd Initial groupbox padding calculation fix. This may still need more work... very simple version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 795
diff changeset
3625 Box *box = [thisbox box];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
3626
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
3627 [groupbox setBorderType:NSBezelBorder];
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
3628 [groupbox setTitle:[NSString stringWithUTF8String:title]];
806
16964b141964 More accurate groupbox paddig calculations. Title rectangle is now calculated on the fly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 805
diff changeset
3629 box->grouphwnd = groupbox;
796
3a3fae1f31bd Initial groupbox padding calculation fix. This may still need more work... very simple version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 795
diff changeset
3630 [groupbox setContentView:thisbox];
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
3631 [thisbox autorelease];
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
3632 return groupbox;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3633 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3634
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3635 /*
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3636 * Create a new scrollable Box to be packed.
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3637 * Parameters:
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3638 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3639 * pad: Number of pixels to pad around the box.
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3640 */
796
3a3fae1f31bd Initial groupbox padding calculation fix. This may still need more work... very simple version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 795
diff changeset
3641 HWND API dw_scrollbox_new( int type, int pad )
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3642 {
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
3643 DWScrollBox *scrollbox = [[DWScrollBox alloc] init];
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
3644 DWBox *box = dw_box_new(type, pad);
840
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
3645 DWBox *tmpbox = dw_box_new(DW_VERT, 0);
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
3646 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0);
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
3647 [scrollbox setHasVerticalScroller:YES];
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
3648 [scrollbox setHasHorizontalScroller:YES];
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
3649 [scrollbox setBorderType:NSNoBorder];
838
8e0405435d0a Minor scrollbox fixes...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 837
diff changeset
3650 [scrollbox setDrawsBackground:NO];
840
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
3651 [scrollbox setBox:box];
2967934fb587 Implemented the fix for the scrollbox problem on the Mac (that was discovered on Windows)
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 838
diff changeset
3652 [scrollbox setDocumentView:tmpbox];
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
3653 [tmpbox autorelease];
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
3654 return scrollbox;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3655 }
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3656
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3657 /*
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3658 * Returns the position of the scrollbar in the scrollbox
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3659 * Parameters:
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3660 * handle: Handle to the scrollbox to be queried.
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3661 * orient: The vertical or horizontal scrollbar.
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3662 */
796
3a3fae1f31bd Initial groupbox padding calculation fix. This may still need more work... very simple version.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 795
diff changeset
3663 int API dw_scrollbox_get_pos(HWND handle, int orient)
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3664 {
844
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3665 DWScrollBox *scrollbox = handle;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3666 NSView *view = [scrollbox documentView];
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3667 NSSize contentsize = [scrollbox contentSize];
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3668 NSScroller *scrollbar;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3669 int range = 0;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3670 int val = 0;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3671 if(orient == DW_VERT)
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3672 {
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3673 scrollbar = [scrollbox verticalScroller];
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3674 range = [view bounds].size.height - contentsize.height;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3675 }
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3676 else
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3677 {
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3678 scrollbar = [scrollbox horizontalScroller];
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3679 range = [view bounds].size.width - contentsize.width;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3680 }
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3681 if(range > 0)
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3682 {
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3683 val = [scrollbar floatValue] * range;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3684 }
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3685 return val;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3686 }
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3687
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3688 /*
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3689 * Gets the range for the scrollbar in the scrollbox.
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3690 * Parameters:
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3691 * handle: Handle to the scrollbox to be queried.
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3692 * orient: The vertical or horizontal scrollbar.
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3693 */
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3694 int API dw_scrollbox_get_range(HWND handle, int orient)
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3695 {
844
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3696 DWScrollBox *scrollbox = handle;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3697 NSView *view = [scrollbox documentView];
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3698 int range = 0;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3699 if(orient == DW_VERT)
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3700 {
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3701 range = [view bounds].size.height;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3702 }
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3703 else
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3704 {
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3705 range = [view bounds].size.width;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3706 }
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3707 return range;
5103d132c3cd Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 840
diff changeset
3708 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
3709
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3710 /* Return the handle to the text object */
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3711 id _text_handle(id object)
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3712 {
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3713 if([object isMemberOfClass:[ DWSpinButton class]])
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3714 {
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3715 DWSpinButton *spinbutton = object;
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3716 object = [spinbutton textfield];
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3717 }
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3718 if([object isMemberOfClass:[ NSBox class]])
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3719 {
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3720 NSBox *box = object;
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3721 id content = [box contentView];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3722
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3723 if([content isMemberOfClass:[ DWText class]])
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3724 {
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3725 object = content;
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3726 }
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3727 }
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3728 return object;
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3729 }
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3730
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3731 /* Internal function to calculate the widget's required size..
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3732 * These are the general rules for widget sizes:
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3733 *
1537
a4ecef1980db Added code for returning a size for scrolled widgets on OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1533
diff changeset
3734 * Render/Unspecified: 1x1
1556
4a9c574d5c17 Fixed on Windows showing themed static text on colored boxes when the window is glass.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1553
diff changeset
3735 * Scrolled(Container,Tree,MLE): Guessed size clamped to min and max in dw.h
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3736 * Entryfield/Combobox/Spinbutton: 150x(maxfontheight)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3737 * Spinbutton: 50x(maxfontheight)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3738 * Text/Status: (textwidth)x(textheight)
1422
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
3739 * Ranged: 100x14 or 14x100 for vertical.
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
3740 * Buttons/Bitmaps: Size of text or image and border.
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
3741 */
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3742 void _control_size(id handle, int *width, int *height)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3743 {
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3744 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3745 NSString *nsstr = nil;
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3746 id object = _text_handle(handle);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3747
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3748 /* Handle all the different button types */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3749 if([ object isKindOfClass:[ NSButton class ] ])
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3750 {
1420
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3751 switch([object buttonType])
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3752 {
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3753 case NSSwitchButton:
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3754 case NSRadioButton:
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3755 extrawidth = 24;
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3756 extraheight = 4;
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3757 nsstr = [object title];
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3758 break;
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3759 default:
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3760 {
1420
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3761 NSImage *image = [object image];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3762
1420
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3763 if(image)
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3764 {
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3765 /* Image button */
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3766 NSSize size = [image size];
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3767 thiswidth = (int)size.width;
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3768 thisheight = (int)size.height;
1432
6aa94c8a91de Bordered bitmap buttons need extra padding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1429
diff changeset
3769 if([object isBordered])
6aa94c8a91de Bordered bitmap buttons need extra padding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1429
diff changeset
3770 {
6aa94c8a91de Bordered bitmap buttons need extra padding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1429
diff changeset
3771 extrawidth = 4;
6aa94c8a91de Bordered bitmap buttons need extra padding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1429
diff changeset
3772 extraheight = 4;
6aa94c8a91de Bordered bitmap buttons need extra padding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1429
diff changeset
3773 }
1420
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3774 }
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3775 else
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3776 {
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3777 /* Text button */
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3778 nsstr = [object title];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3779
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3780 if([object isBordered])
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3781 {
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3782 extrawidth = 30;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3783 extraheight = 8;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3784 }
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3785 else
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3786 {
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3787 extrawidth = 8;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3788 extraheight = 4;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3789 }
1420
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3790 }
fabf23bdc7fb New Mac image button handling code was catching checkboxes/radiobuttons as well.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1419
diff changeset
3791 break;
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3792 }
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3793 }
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3794 }
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3795 /* If the control is an entryfield set width to 150 */
1791
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3796 else if([object isKindOfClass:[ NSTextField class ]])
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3797 {
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3798 NSFont *font = [object font];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3799
1791
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3800 if([object isEditable])
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3801 {
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3802 /* Spinbuttons don't need to be as wide */
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3803 if([object isMemberOfClass:[ DWSpinButton class]])
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3804 thiswidth = 50;
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3805 else
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3806 thiswidth = 150;
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3807 /* Spinbuttons don't need to be as wide */
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3808 if([object isMemberOfClass:[ DWComboBox class]])
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3809 extraheight = 4;
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3810 }
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3811 else
1791
ed8851658015 Set status text fields in the test program to auto height... because they were too small on Mac.... this caused me to notice a bug in the calculation of (status) text widgets when the text is empty; this also contains a fix for that bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1788
diff changeset
3812 nsstr = [object stringValue];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3813
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3814 if(font)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3815 thisheight = (int)[font boundingRectForFont].size.height;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3816 }
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3817 /* Handle the ranged widgets */
1457
c22477fe7347 Split out scrollbars from the rest of the ranged widgets on Mac... the others require extra size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1453
diff changeset
3818 else if([ object isMemberOfClass:[DWPercent class] ] ||
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3819 [ object isMemberOfClass:[DWSlider class] ])
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3820 {
1457
c22477fe7347 Split out scrollbars from the rest of the ranged widgets on Mac... the others require extra size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1453
diff changeset
3821 thiswidth = 100;
c22477fe7347 Split out scrollbars from the rest of the ranged widgets on Mac... the others require extra size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1453
diff changeset
3822 thisheight = 20;
c22477fe7347 Split out scrollbars from the rest of the ranged widgets on Mac... the others require extra size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1453
diff changeset
3823 }
c22477fe7347 Split out scrollbars from the rest of the ranged widgets on Mac... the others require extra size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1453
diff changeset
3824 /* Handle the ranged widgets */
c22477fe7347 Split out scrollbars from the rest of the ranged widgets on Mac... the others require extra size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1453
diff changeset
3825 else if([ object isMemberOfClass:[DWScrollbar class] ])
c22477fe7347 Split out scrollbars from the rest of the ranged widgets on Mac... the others require extra size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1453
diff changeset
3826 {
c22477fe7347 Split out scrollbars from the rest of the ranged widgets on Mac... the others require extra size.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1453
diff changeset
3827 if([object vertical])
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3828 {
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3829 thiswidth = 14;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3830 thisheight = 100;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3831 }
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3832 else
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3833 {
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3834 thiswidth = 100;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3835 thisheight = 14;
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3836 }
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
3837 }
1421
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3838 /* Handle bitmap size */
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3839 else if([ object isMemberOfClass:[NSImageView class] ])
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3840 {
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3841 NSImage *image = [object image];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3842
1421
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3843 if(image)
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3844 {
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3845 NSSize size = [image size];
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3846 thiswidth = (int)size.width;
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3847 thisheight = (int)size.height;
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3848 }
63d253a2cdd9 Added bitmap autosizing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1420
diff changeset
3849 }
1533
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3850 /* Handle calendar */
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3851 else if([ object isMemberOfClass:[DWCalendar class] ])
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3852 {
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3853 NSCell *cell = [object cell];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3854
1533
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3855 if(cell)
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3856 {
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3857 NSSize size = [cell cellSize];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3858
1533
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3859 thiswidth = size.width;
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3860 thisheight = size.height;
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3861 }
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3862 }
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3863 /* MLE and Container */
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3864 else if([ object isMemberOfClass:[DWMLE class] ] ||
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3865 [ object isMemberOfClass:[DWContainer class] ])
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3866 {
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3867 NSSize size;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3868
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3869 if([ object isMemberOfClass:[DWMLE class] ])
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3870 {
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3871 NSScrollView *sv = [object scrollview];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3872 NSSize frame = [sv frame].size;
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3873 BOOL hscroll = [sv hasHorizontalScroller];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3874
1552
f00f91d15cbf Added additional code to MLE calculations on Mac to take into account the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1551
diff changeset
3875 /* Make sure word wrap is off for the first part */
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3876 if(!hscroll)
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3877 {
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3878 [[object textContainer] setWidthTracksTextView:NO];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3879 [[object textContainer] setContainerSize:[object maxSize]];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3880 [object setHorizontallyResizable:YES];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3881 [sv setHasHorizontalScroller:YES];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3882 }
1552
f00f91d15cbf Added additional code to MLE calculations on Mac to take into account the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1551
diff changeset
3883 /* Size the text view to fit */
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3884 [object sizeToFit];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3885 size = [object bounds].size;
1552
f00f91d15cbf Added additional code to MLE calculations on Mac to take into account the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1551
diff changeset
3886 size.width += 2.0;
f00f91d15cbf Added additional code to MLE calculations on Mac to take into account the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1551
diff changeset
3887 size.height += 2.0;
f00f91d15cbf Added additional code to MLE calculations on Mac to take into account the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1551
diff changeset
3888 /* Re-enable word wrapping if it was on */
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3889 if(!hscroll)
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3890 {
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3891 [[object textContainer] setWidthTracksTextView:YES];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3892 [sv setHasHorizontalScroller:NO];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3893
1553
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3894 /* If the un wrapped it is beyond the bounds... */
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3895 if(size.width > _DW_SCROLLED_MAX_WIDTH)
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3896 {
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3897 NSSize max = [object maxSize];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3898
1553
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3899 /* Set the max size to the limit */
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3900 [object setMaxSize:NSMakeSize(_DW_SCROLLED_MAX_WIDTH, max.height)];
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3901 /* Recalculate the size */
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3902 [object sizeToFit];
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3903 size = [object bounds].size;
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3904 size.width += 2.0;
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3905 size.height += 2.0;
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3906 [object setMaxSize:max];
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3907 }
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3908 }
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3909 [sv setFrameSize:frame];
1552
f00f91d15cbf Added additional code to MLE calculations on Mac to take into account the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1551
diff changeset
3910 /* Take into account the horizontal scrollbar */
1553
46a2123ff570 Cleanup of the previous commits on Mac, don't do more calculations than we need to.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1552
diff changeset
3911 if(hscroll && size.width > _DW_SCROLLED_MAX_WIDTH)
1552
f00f91d15cbf Added additional code to MLE calculations on Mac to take into account the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1551
diff changeset
3912 size.height += 16.0;
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3913 }
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3914 else
1573
d6e17c8f4de2 Fixed container and listbox not accounting for contents on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1566
diff changeset
3915 size = [object getsize];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3916
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3917 thiswidth = size.width;
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3918 thisheight = size.height;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3919
1549
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3920 if(thiswidth < _DW_SCROLLED_MIN_WIDTH)
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3921 thiswidth = _DW_SCROLLED_MIN_WIDTH;
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3922 if(thiswidth > _DW_SCROLLED_MAX_WIDTH)
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3923 thiswidth = _DW_SCROLLED_MAX_WIDTH;
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3924 if(thisheight < _DW_SCROLLED_MIN_HEIGHT)
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3925 thisheight = _DW_SCROLLED_MIN_HEIGHT;
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3926 if(thisheight > _DW_SCROLLED_MAX_HEIGHT)
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3927 thisheight = _DW_SCROLLED_MAX_HEIGHT;
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
3928 }
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3929 /* Tree */
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
3930 else if([ object isMemberOfClass:[DWTree class] ])
1537
a4ecef1980db Added code for returning a size for scrolled widgets on OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1533
diff changeset
3931 {
1566
035bc006afbe Experimental change... halfway between min and max for tree controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1564
diff changeset
3932 thiswidth = (int)((_DW_SCROLLED_MAX_WIDTH + _DW_SCROLLED_MIN_WIDTH)/2);
035bc006afbe Experimental change... halfway between min and max for tree controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1564
diff changeset
3933 thisheight = (int)((_DW_SCROLLED_MAX_HEIGHT + _DW_SCROLLED_MIN_HEIGHT)/2);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3934 }
1533
7bc189ef0cd0 Add code to determine the size of the calendar control on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1531
diff changeset
3935 /* Any other control type */
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3936 else if([ object isKindOfClass:[ NSControl class ] ])
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3937 nsstr = [object stringValue];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3938
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3939 /* If we have a string...
1564
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
3940 * calculate the size with the current font.
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
3941 */
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
3942 if(nsstr && [nsstr length])
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
3943 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3944
1418
461240f946d0 Status text fields needs extra space on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1411
diff changeset
3945 /* Handle static text fields */
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3946 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable])
1418
461240f946d0 Status text fields needs extra space on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1411
diff changeset
3947 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3948 id border = handle;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3949
1778
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
3950 extrawidth = 10;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3951
1418
461240f946d0 Status text fields needs extra space on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1411
diff changeset
3952 /* Handle status bar field */
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3953 if([border isMemberOfClass:[ NSBox class ] ])
1564
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
3954 {
1778
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
3955 extrawidth += 2;
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
3956 extraheight = 8;
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
3957 }
1418
461240f946d0 Status text fields needs extra space on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1411
diff changeset
3958 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
3959
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
3960 /* Set the requested sizes */
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3961 if(width)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3962 *width = thiswidth + extrawidth;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3963 if(height)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3964 *height = thisheight + extraheight;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3965 }
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
3966
1086
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3967 /* Internal box packing function called by the other 3 functions */
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3968 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname)
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3969 {
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3970 int _locked_by_me = FALSE;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3971 DW_MUTEX_LOCK;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3972 id object = box;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3973 DWBox *view = box;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3974 DWBox *this = item;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3975 Box *thisbox;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3976 int z, x = 0;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3977 Item *tmpitem, *thisitem;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3978
1086
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3979 /*
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3980 * If you try and pack an item into itself VERY bad things can happen; like at least an
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3981 * infinite loop on GTK! Lets be safe!
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3982 */
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3983 if(box == item)
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3984 {
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3985 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3986 return;
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
3987 }
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
3988
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3989 /* Query the objects */
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3990 if([ object isKindOfClass:[ NSWindow class ] ])
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3991 {
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3992 NSWindow *window = box;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3993 view = [window contentView];
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3994 }
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3995 else if([ object isMemberOfClass:[ DWScrollBox class ] ])
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3996 {
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3997 DWScrollBox *scrollbox = box;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3998 view = [scrollbox box];
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
3999 }
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4000
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4001 thisbox = [view box];
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4002 thisitem = thisbox->items;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4003 object = item;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4004
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4005 /* Query the objects */
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
4006 if([ object isMemberOfClass:[ DWContainer class ] ] ||
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
4007 [ object isMemberOfClass:[ DWTree class ] ] ||
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
4008 [ object isMemberOfClass:[ DWMLE class ] ])
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
4009 {
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
4010 this = item = [object scrollview];
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4011 }
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4012
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4013 /* Do some sanity bounds checking */
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4014 if(!thisitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4015 thisbox->count = 0;
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4016 if(index < 0)
1079
5d3acda4acd4 Fixed a minor cut and paste error and formatting on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1077
diff changeset
4017 index = 0;
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4018 if(index > thisbox->count)
1079
5d3acda4acd4 Fixed a minor cut and paste error and formatting on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1077
diff changeset
4019 index = thisbox->count;
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
4020
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4021 /* Duplicate the existing data */
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4022 tmpitem = calloc(sizeof(Item), (thisbox->count+1));
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4023
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4024 for(z=0;z<thisbox->count;z++)
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4025 {
1079
5d3acda4acd4 Fixed a minor cut and paste error and formatting on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1077
diff changeset
4026 if(z == index)
5d3acda4acd4 Fixed a minor cut and paste error and formatting on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1077
diff changeset
4027 x++;
5d3acda4acd4 Fixed a minor cut and paste error and formatting on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1077
diff changeset
4028 tmpitem[x] = thisitem[z];
5d3acda4acd4 Fixed a minor cut and paste error and formatting on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1077
diff changeset
4029 x++;
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4030 }
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4031
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4032 /* Sanity checks */
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4033 if(vsize && !height)
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4034 height = 1;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4035 if(hsize && !width)
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4036 width = 1;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4037
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4038 /* Fill in the item data appropriately */
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4039 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]])
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4040 tmpitem[index].type = TYPEBOX;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4041 else
1086
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4042 {
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4043 if ( width == 0 && hsize == FALSE )
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4044 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4045 if ( height == 0 && vsize == FALSE )
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4046 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
4047
1086
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4048 tmpitem[index].type = TYPEITEM;
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4049 }
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4050
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4051 tmpitem[index].hwnd = item;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4052 tmpitem[index].origwidth = tmpitem[index].width = width;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4053 tmpitem[index].origheight = tmpitem[index].height = height;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4054 tmpitem[index].pad = pad;
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
4055 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
4056 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4057
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
4058 /* If either of the parameters are -1 ... calculate the size */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
4059 if(width == -1 || height == -1)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
4060 _control_size(object, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL);
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4061
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4062 thisbox->items = tmpitem;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4063
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4064 /* Update the item count */
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4065 thisbox->count++;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4066
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4067 /* Add the item to the box */
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4068 [view addSubview:this];
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
4069 /* Enable autorelease on the item...
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
4070 * so it will get destroyed when the parent is.
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
4071 */
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
4072 [this autorelease];
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4073 /* If we are packing a button... */
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4074 if([this isMemberOfClass:[DWButton class]])
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4075 {
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4076 DWButton *button = (DWButton *)this;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4078 /* Save the parent box so radio
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4079 * buttons can use it later.
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4080 */
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4081 [button setParent:view];
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4082 }
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
4083 /* Queue a redraw on the top-level window */
1673
db393069b27d Fix packing padding not triggering automatic redraws on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1672
diff changeset
4084 _dw_redraw([view window], TRUE);
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4085
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4086 /* Free the old data */
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4087 if(thisitem)
1077
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4088 free(thisitem);
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4089 DW_MUTEX_UNLOCK;
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4090 }
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4091
34f1d6f5f1c3 Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1075
diff changeset
4092 /*
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4093 * Remove windows (widgets) from the box they are packed into.
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4094 * Parameters:
1679
e19b93a8229b More comment cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1678
diff changeset
4095 * handle: Window handle of the packed item to be removed.
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4096 * Returns:
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4097 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure.
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4098 */
1769
d81bebc5c8cc Mark and I decided to change dw_box_remove*() to dw_box_unpack*() for consistency.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1764
diff changeset
4099 int API dw_box_unpack(HWND handle)
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4100 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4101 int _locked_by_me = FALSE;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4102 DW_LOCAL_POOL_IN;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4103 DW_MUTEX_LOCK;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4104 id object = handle;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4105
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4106 if([object isKindOfClass:[NSView class]] || [object isKindOfClass:[NSControl class]])
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4107 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4108 DWBox *parent = (DWBox *)[object superview];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4109
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4110 /* Some controls are embedded in scrollviews...
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4111 * so get the parent of the scrollview in that case.
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4112 */
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4113 if(([object isKindOfClass:[NSTableView class]] || [object isMemberOfClass:[DWMLE class]])
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4114 && [parent isMemberOfClass:[NSClipView class]])
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4115 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4116 object = [parent superview];
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4117 parent = (DWBox *)[object superview];
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4118 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4119
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4120 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]])
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4121 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4122 id window = [object window];
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4123 Box *thisbox = [parent box];
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4124 int z, index = -1;
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4125 Item *tmpitem = NULL, *thisitem = thisbox->items;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4126
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4127 if(!thisitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4128 thisbox->count = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4129
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4130 for(z=0;z<thisbox->count;z++)
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4131 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4132 if(thisitem[z].hwnd == object)
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4133 index = z;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4134 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4135
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4136 if(index == -1)
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4137 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4138 DW_MUTEX_UNLOCK;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4139 DW_LOCAL_POOL_OUT;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4140 return DW_ERROR_GENERAL;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4141 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4142
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4143 [object retain];
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4144 [object removeFromSuperview];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4145
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4146 if(thisbox->count > 1)
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4147 {
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4148 tmpitem = calloc(sizeof(Item), (thisbox->count-1));
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4149
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4150 /* Copy all but the current entry to the new list */
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4151 for(z=0;z<index;z++)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4152 {
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4153 tmpitem[z] = thisitem[z];
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4154 }
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4155 for(z=index+1;z<thisbox->count;z++)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4156 {
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4157 tmpitem[z-1] = thisitem[z];
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4158 }
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4159 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4160
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4161 thisbox->items = tmpitem;
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4162 if(thisitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4163 free(thisitem);
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4164 if(tmpitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4165 thisbox->count--;
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4166 else
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4167 thisbox->count = 0;
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4168 /* Queue a redraw on the top-level window */
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4169 _dw_redraw(window, TRUE);
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4170 }
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4171 }
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4172 DW_MUTEX_UNLOCK;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4173 DW_LOCAL_POOL_OUT;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4174 return DW_ERROR_NONE;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4175 }
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4176
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4177 /*
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4178 * Remove windows (widgets) from a box at an arbitrary location.
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4179 * Parameters:
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4180 * box: Window handle of the box to be removed from.
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4181 * index: 0 based index of packed items.
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4182 * Returns:
1679
e19b93a8229b More comment cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1678
diff changeset
4183 * Handle to the removed item on success, 0 on failure or padding.
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4184 */
1769
d81bebc5c8cc Mark and I decided to change dw_box_remove*() to dw_box_unpack*() for consistency.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1764
diff changeset
4185 HWND API dw_box_unpack_at_index(HWND box, int index)
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4186 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4187 int _locked_by_me = FALSE;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4188 DW_LOCAL_POOL_IN;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4189 DW_MUTEX_LOCK;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4190 DWBox *parent = (DWBox *)box;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4191 id object = nil;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4192
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4193 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]])
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4194 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4195 id window = [parent window];
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4196 Box *thisbox = [parent box];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4197
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4198 if(thisbox && index > -1 && index < thisbox->count)
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4199 {
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4200 int z;
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4201 Item *tmpitem = NULL, *thisitem = thisbox->items;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4202
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4203 object = thisitem[index].hwnd;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4204
1672
42890a2b8d3e Fix minor issues with dw_box_remove_at_index() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1671
diff changeset
4205 if(object)
42890a2b8d3e Fix minor issues with dw_box_remove_at_index() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1671
diff changeset
4206 {
42890a2b8d3e Fix minor issues with dw_box_remove_at_index() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1671
diff changeset
4207 [object retain];
42890a2b8d3e Fix minor issues with dw_box_remove_at_index() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1671
diff changeset
4208 [object removeFromSuperview];
42890a2b8d3e Fix minor issues with dw_box_remove_at_index() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1671
diff changeset
4209 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4210
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4211 if(thisbox->count > 1)
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4212 {
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4213 tmpitem = calloc(sizeof(Item), (thisbox->count-1));
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4214
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4215 /* Copy all but the current entry to the new list */
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4216 for(z=0;thisitem && z<index;z++)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4217 {
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4218 tmpitem[z] = thisitem[z];
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4219 }
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4220 for(z=index+1;z<thisbox->count;z++)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4221 {
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4222 tmpitem[z-1] = thisitem[z];
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4223 }
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4224 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4225
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4226 thisbox->items = tmpitem;
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4227 if(thisitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4228 free(thisitem);
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4229 if(tmpitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4230 thisbox->count--;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4231 else
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
4232 thisbox->count = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
4233
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4234 /* Queue a redraw on the top-level window */
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4235 _dw_redraw(window, TRUE);
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4236 }
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4237 }
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4238 DW_MUTEX_UNLOCK;
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4239 DW_LOCAL_POOL_OUT;
1672
42890a2b8d3e Fix minor issues with dw_box_remove_at_index() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1671
diff changeset
4240 return object;
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4241 }
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4242
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
4243 /*
1086
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4244 * Pack windows (widgets) into a box at an arbitrary location.
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4245 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4246 * box: Window handle of the box to be packed into.
1678
896f377a47c7 Added exports for building with MinGW on Windows and Watcom on OS/2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1673
diff changeset
4247 * item: Window handle of the item to pack.
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
4248 * index: 0 based index of packed items.
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4249 * width: Width in pixels of the item or -1 to be self determined.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4250 * height: Height in pixels of the item or -1 to be self determined.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4251 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4252 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4253 * pad: Number of pixels of padding around the item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4254 */
1086
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4255 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4256 {
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4257 _dw_box_pack(box, item, index, width, height, hsize, vsize, pad, "dw_box_pack_at_index()");
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4258 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4259
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4260 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4261 * Pack windows (widgets) into a box from the start (or top).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4262 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4263 * box: Window handle of the box to be packed into.
1678
896f377a47c7 Added exports for building with MinGW on Windows and Watcom on OS/2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1673
diff changeset
4264 * item: Window handle of the item to pack.
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4265 * width: Width in pixels of the item or -1 to be self determined.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4266 * height: Height in pixels of the item or -1 to be self determined.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4267 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4268 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4269 * pad: Number of pixels of padding around the item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4270 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4271 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4272 {
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
4273 /* 65536 is the table limit on GTK...
1086
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4274 * seems like a high enough value we will never hit it here either.
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4275 */
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4276 _dw_box_pack(box, item, 65536, width, height, hsize, vsize, pad, "dw_box_pack_start()");
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4277 }
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4278
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4279 /*
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4280 * Pack windows (widgets) into a box from the end (or bottom).
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4281 * Parameters:
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4282 * box: Window handle of the box to be packed into.
1678
896f377a47c7 Added exports for building with MinGW on Windows and Watcom on OS/2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1673
diff changeset
4283 * item: Window handle of the item to pack.
1086
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4284 * width: Width in pixels of the item or -1 to be self determined.
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4285 * height: Height in pixels of the item or -1 to be self determined.
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4286 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4287 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4288 * pad: Number of pixels of padding around the item.
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4289 */
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4290 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4291 {
4254c9b6d50d Merge all 3 box packing functions into one internal function on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1079
diff changeset
4292 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()");
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4293 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4294
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4295 HWND _button_new(char *text, ULONG cid)
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4296 {
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4297 DWButton *button = [[DWButton alloc] init];
983
6abf763838c6 Allow checboxes and other "buttons" to have a blank title instead of the default "Button"
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 982
diff changeset
4298 if(text)
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4299 {
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4300 [button setTitle:[ NSString stringWithUTF8String:text ]];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4301 }
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4302 [button setTarget:button];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4303 [button setAction:@selector(buttonClicked:)];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4304 [button setTag:cid];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4305 [button setButtonType:NSMomentaryPushInButton];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4306 [button setBezelStyle:NSThickerSquareBezelStyle];
1093
25707e9f5ad1 Reverted the image scaling on buttons on Mac so it remains consistent on other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1086
diff changeset
4307 /* TODO: Reenable scaling in the future if it is possible on other platforms.
25707e9f5ad1 Reverted the image scaling on buttons on Mac so it remains consistent on other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1086
diff changeset
4308 [[button cell] setImageScaling:NSImageScaleProportionallyDown]; */
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4309 if(DWDefaultFont)
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4310 {
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4311 [[button cell] setFont:DWDefaultFont];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
4312 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4313 return button;
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4314 }
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4315
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4316 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4317 * Create a new button window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4318 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4319 * text: The text to be display by the static text widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4320 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4321 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4322 HWND API dw_button_new(char *text, ULONG cid)
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4323 {
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4324 DWButton *button = _button_new(text, cid);
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4325 [button setButtonType:NSMomentaryPushInButton];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4326 [button setBezelStyle:NSRoundedBezelStyle];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4327 [button setImagePosition:NSNoImage];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4328 [button setAlignment:NSCenterTextAlignment];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4329 [[button cell] setControlTint:NSBlueControlTint];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4330 return button;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4331 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4332
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4333 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4334 * Create a new Entryfield window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4335 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4336 * text: The default text to be in the entryfield widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4337 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4338 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4339 HWND API dw_entryfield_new(char *text, ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4340 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4341 DWEntryField *entry = [[DWEntryField alloc] init];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4342 [entry setStringValue:[ NSString stringWithUTF8String:text ]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4343 [entry setTag:cid];
1712
daa59fc8d6e5 Disable wrapping on entryfields and static text on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1709
diff changeset
4344 [[entry cell] setScrollable:YES];
daa59fc8d6e5 Disable wrapping on entryfields and static text on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1709
diff changeset
4345 [[entry cell] setWraps:NO];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4346 return entry;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4347 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4348
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4349 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4350 * Create a new Entryfield (password) window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4351 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4352 * text: The default text to be in the entryfield widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4353 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4354 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4355 HWND API dw_entryfield_password_new(char *text, ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4356 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4357 DWEntryFieldPassword *entry = [[DWEntryFieldPassword alloc] init];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4358 [entry setStringValue:[ NSString stringWithUTF8String:text ]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4359 [entry setTag:cid];
1712
daa59fc8d6e5 Disable wrapping on entryfields and static text on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1709
diff changeset
4360 [[entry cell] setScrollable:YES];
daa59fc8d6e5 Disable wrapping on entryfields and static text on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1709
diff changeset
4361 [[entry cell] setWraps:NO];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4362 return entry;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4363 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4364
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4365 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4366 * Sets the entryfield character limit.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4367 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4368 * handle: Handle to the spinbutton to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4369 * limit: Number of characters the entryfield will take.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4370 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4371 void API dw_entryfield_set_limit(HWND handle, ULONG limit)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4372 {
887
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
4373 DWEntryField *entry = handle;
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
4374 DWEntryFieldFormatter *formatter = [[[DWEntryFieldFormatter alloc] init] autorelease];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
4375
887
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
4376 [formatter setMaximumLength:(int)limit];
29d8ae25a78c Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 886
diff changeset
4377 [[entry cell] setFormatter:formatter];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4378 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4379
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4380 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4381 * Create a new bitmap button window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4382 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4383 * text: Bubble help text to be displayed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4384 * id: An ID of a bitmap in the resource file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4385 */
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
4386 HWND API dw_bitmapbutton_new(char *text, ULONG resid)
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
4387 {
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
4388 NSBundle *bundle = [NSBundle mainBundle];
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
4389 NSString *respath = [bundle resourcePath];
1770
2396655d43f1 Fix some warnings with Mac 10.8 and Xcode 4.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1769
diff changeset
4390 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid];
749
9e147366147b Code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 748
diff changeset
4391 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath];
9e147366147b Code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 748
diff changeset
4392 DWButton *button = _button_new("", resid);
748
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4393 if(image)
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4394 {
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4395 [button setImage:image];
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4396 }
1396
117cc38a3799 Allow on Mac passing NULL as bubbletext to dw_bitmapbutton_new*.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1389
diff changeset
4397 if(text)
117cc38a3799 Allow on Mac passing NULL as bubbletext to dw_bitmapbutton_new*.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1389
diff changeset
4398 [button setToolTip:[NSString stringWithUTF8String:text]];
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
4399 [image release];
749
9e147366147b Code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 748
diff changeset
4400 return button;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4401 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4402
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4403 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4404 * Create a new bitmap button window (widget) to be packed from a file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4405 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4406 * text: Bubble help text to be displayed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4407 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4408 * filename: Name of the file, omit extention to have
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4409 * DW pick the appropriate file extension.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4410 * (BMP on OS/2 or Windows, XPM on Unix)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4411 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4412 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long cid, char *filename)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4413 {
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
4414 char *ext = _dw_get_image_extension( filename );
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
4415
674
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
4416 NSString *nstr = [ NSString stringWithUTF8String:filename ];
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
4417 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
4418
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
4419 if(!image && ext)
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
4420 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
4421 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
674
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
4422 image = [[NSImage alloc] initWithContentsOfFile:nstr];
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
4423 }
749
9e147366147b Code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 748
diff changeset
4424 DWButton *button = _button_new("", cid);
748
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4425 if(image)
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4426 {
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4427 [button setImage:image];
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4428 }
1396
117cc38a3799 Allow on Mac passing NULL as bubbletext to dw_bitmapbutton_new*.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1389
diff changeset
4429 if(text)
117cc38a3799 Allow on Mac passing NULL as bubbletext to dw_bitmapbutton_new*.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1389
diff changeset
4430 [button setToolTip:[NSString stringWithUTF8String:text]];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4431 [image release];
749
9e147366147b Code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 748
diff changeset
4432 return button;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4433 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4434
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4435 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4436 * Create a new bitmap button window (widget) to be packed from data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4437 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4438 * text: Bubble help text to be displayed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4439 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4440 * data: The contents of the image
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4441 * (BMP or ICO on OS/2 or Windows, XPM on Unix)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4442 * len: length of str
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4443 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4444 HWND API dw_bitmapbutton_new_from_data(char *text, unsigned long cid, char *data, int len)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4445 {
760
2fb17622a455 Possible fix for exception in dw_bitmapbutton_new_from_data()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 755
diff changeset
4446 NSData *thisdata = [NSData dataWithBytes:data length:len];
749
9e147366147b Code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 748
diff changeset
4447 NSImage *image = [[NSImage alloc] initWithData:thisdata];
9e147366147b Code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 748
diff changeset
4448 DWButton *button = _button_new("", cid);
748
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4449 if(image)
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4450 {
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4451 [button setImage:image];
f39745844175 Added tooltips to bitmap buttons... and made a change to the look when the image is present...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 747
diff changeset
4452 }
1396
117cc38a3799 Allow on Mac passing NULL as bubbletext to dw_bitmapbutton_new*.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1389
diff changeset
4453 if(text)
117cc38a3799 Allow on Mac passing NULL as bubbletext to dw_bitmapbutton_new*.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1389
diff changeset
4454 [button setToolTip:[NSString stringWithUTF8String:text]];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4455 [image release];
749
9e147366147b Code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 748
diff changeset
4456 return button;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4457 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4458
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4459 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4460 * Create a new spinbutton window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4461 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4462 * text: The text to be display by the static text widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4463 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4464 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4465 HWND API dw_spinbutton_new(char *text, ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4466 {
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4467 DWSpinButton *spinbutton = [[DWSpinButton alloc] init];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4468 NSStepper *stepper = [spinbutton stepper];
1023
8188f818eb9f Changed initial spinbutton limits to -65536 to 65536 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1018
diff changeset
4469 NSTextField *textfield = [spinbutton textfield];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4470 [stepper setIncrement:1];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4471 [stepper setTag:cid];
1023
8188f818eb9f Changed initial spinbutton limits to -65536 to 65536 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1018
diff changeset
4472 [stepper setMinValue:-65536];
8188f818eb9f Changed initial spinbutton limits to -65536 to 65536 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1018
diff changeset
4473 [stepper setMaxValue:65536];
8188f818eb9f Changed initial spinbutton limits to -65536 to 65536 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1018
diff changeset
4474 [stepper setIntValue:atoi(text)];
8188f818eb9f Changed initial spinbutton limits to -65536 to 65536 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1018
diff changeset
4475 [textfield takeIntValueFrom:stepper];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4476 return spinbutton;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4477 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4478
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4479 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4480 * Sets the spinbutton value.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4481 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4482 * handle: Handle to the spinbutton to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4483 * position: Current value of the spinbutton.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4484 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4485 void API dw_spinbutton_set_pos(HWND handle, long position)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4486 {
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4487 DWSpinButton *spinbutton = handle;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4488 NSStepper *stepper = [spinbutton stepper];
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
4489 NSTextField *textfield = [spinbutton textfield];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4490 [stepper setIntValue:(int)position];
679
d2d7d1802af4 Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 678
diff changeset
4491 [textfield takeIntValueFrom:stepper];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4492 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4493
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4494 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4495 * Sets the spinbutton limits.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4496 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4497 * handle: Handle to the spinbutton to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4498 * upper: Upper limit.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4499 * lower: Lower limit.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4500 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4501 void API dw_spinbutton_set_limits(HWND handle, long upper, long lower)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4502 {
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4503 DWSpinButton *spinbutton = handle;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4504 NSStepper *stepper = [spinbutton stepper];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4505 [stepper setMinValue:(double)lower];
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4506 [stepper setMaxValue:(double)upper];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4507 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4508
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4509 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4510 * Returns the current value of the spinbutton.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4511 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4512 * handle: Handle to the spinbutton to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4513 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4514 long API dw_spinbutton_get_pos(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4515 {
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4516 DWSpinButton *spinbutton = handle;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4517 NSStepper *stepper = [spinbutton stepper];
678
0ec8edbb82cf Basic spinbutton implementation, something isn't quite working right but
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 677
diff changeset
4518 return (long)[stepper integerValue];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4519 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4520
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4521 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4522 * Create a new radiobutton window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4523 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4524 * text: The text to be display by the static text widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4525 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4526 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4527 HWND API dw_radiobutton_new(char *text, ULONG cid)
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4528 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4529 DWButton *button = _button_new(text, cid);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4530 [button setButtonType:NSRadioButton];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4531 return button;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4532 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4533
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4534 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4535 * Create a new slider window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4536 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4537 * vertical: TRUE or FALSE if slider is vertical.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4538 * increments: Number of increments available.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4539 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4540 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4541 HWND API dw_slider_new(int vertical, int increments, ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4542 {
704
336800e9e648 Fixes to the slider control so events happen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 703
diff changeset
4543 DWSlider *slider = [[DWSlider alloc] init];
336800e9e648 Fixes to the slider control so events happen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 703
diff changeset
4544 [slider setMaxValue:(double)increments];
336800e9e648 Fixes to the slider control so events happen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 703
diff changeset
4545 [slider setMinValue:0];
336800e9e648 Fixes to the slider control so events happen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 703
diff changeset
4546 [slider setContinuous:YES];
336800e9e648 Fixes to the slider control so events happen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 703
diff changeset
4547 [slider setTarget:slider];
336800e9e648 Fixes to the slider control so events happen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 703
diff changeset
4548 [slider setAction:@selector(sliderChanged:)];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4549 [slider setTag:cid];
704
336800e9e648 Fixes to the slider control so events happen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 703
diff changeset
4550 return slider;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4551 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4552
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4553 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4554 * Returns the position of the slider.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4555 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4556 * handle: Handle to the slider to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4557 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4558 unsigned int API dw_slider_get_pos(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4559 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4560 DWSlider *slider = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4561 double val = [slider doubleValue];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4562 return (int)val;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4563 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4564
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4565 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4566 * Sets the slider position.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4567 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4568 * handle: Handle to the slider to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4569 * position: Position of the slider withing the range.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4570 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4571 void API dw_slider_set_pos(HWND handle, unsigned int position)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4572 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4573 DWSlider *slider = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4574 [slider setDoubleValue:(double)position];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4575 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4576
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4577 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4578 * Create a new scrollbar window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4579 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4580 * vertical: TRUE or FALSE if scrollbar is vertical.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4581 * increments: Number of increments available.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4582 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4583 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4584 HWND API dw_scrollbar_new(int vertical, ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4585 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4586 DWScrollbar *scrollbar;
689
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4587 if(vertical)
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4588 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4589 scrollbar = [[DWScrollbar alloc] init];
1419
8827e9b14b40 Initial support for automatic window redrawing on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1418
diff changeset
4590 [scrollbar setVertical:YES];
689
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4591 }
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4592 else
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4593 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4594 scrollbar = [[DWScrollbar alloc] initWithFrame:NSMakeRect(0,0,100,5)];
689
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4595 }
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4596 [scrollbar setArrowsPosition:NSScrollerArrowsDefaultSetting];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4597 [scrollbar setTarget:scrollbar];
689
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4598 [scrollbar setAction:@selector(changed:)];
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4599 [scrollbar setRange:0.0 andVisible:0.0];
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4600 [scrollbar setKnobProportion:1.0];
705
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
4601 [scrollbar setTarget:scrollbar];
7087f3a294e5 Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 704
diff changeset
4602 [scrollbar setAction:@selector(scrollerChanged:)];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4603 [scrollbar setTag:cid];
689
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4604 [scrollbar setEnabled:YES];
4199730e9889 Fixed errors creating scrollbars.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 688
diff changeset
4605 return scrollbar;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4606 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4607
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4608 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4609 * Returns the position of the scrollbar.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4610 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4611 * handle: Handle to the scrollbar to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4612 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4613 unsigned int API dw_scrollbar_get_pos(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4614 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4615 DWScrollbar *scrollbar = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4616 float range = [scrollbar range];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4617 float fresult = [scrollbar doubleValue] * range;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4618 return (int)fresult;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4619 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4620
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4621 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4622 * Sets the scrollbar position.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4623 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4624 * handle: Handle to the scrollbar to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4625 * position: Position of the scrollbar withing the range.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4626 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4627 void API dw_scrollbar_set_pos(HWND handle, unsigned int position)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4628 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4629 DWScrollbar *scrollbar = handle;
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
4630 double range = [scrollbar range];
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
4631 double visible = [scrollbar visible];
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
4632 double newpos = (double)position/(range-visible);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4633 [scrollbar setDoubleValue:newpos];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4634 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4635
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4636 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4637 * Sets the scrollbar range.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4638 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4639 * handle: Handle to the scrollbar to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4640 * range: Maximum range value.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4641 * visible: Visible area relative to the range.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4642 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4643 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4644 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4645 DWScrollbar *scrollbar = handle;
933
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
4646 double knob = (double)visible/(double)range;
b19e6e55fc8e Rewrote the scrollbar handler with a more accurate method and fixed a bug setting the position on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 932
diff changeset
4647 [scrollbar setRange:(double)range andVisible:(double)visible];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4648 [scrollbar setKnobProportion:knob];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4649 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4651 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4652 * Create a new percent bar window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4653 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4654 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4655 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4656 HWND API dw_percent_new(ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4657 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4658 DWPercent *percent = [[DWPercent alloc] init];
714
cf6246f86c04 Fixed the percent/progress indicators from always being indeterminate.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 713
diff changeset
4659 [percent setStyle:NSProgressIndicatorBarStyle];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4660 [percent setBezeled:YES];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4661 [percent setMaxValue:100];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4662 [percent setMinValue:0];
714
cf6246f86c04 Fixed the percent/progress indicators from always being indeterminate.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 713
diff changeset
4663 [percent incrementBy:1];
cf6246f86c04 Fixed the percent/progress indicators from always being indeterminate.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 713
diff changeset
4664 [percent setIndeterminate:NO];
1586
021d2966f84d Make sure the percent widget defaults to 0% on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1582
diff changeset
4665 [percent setDoubleValue:0];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4666 /*[percent setTag:cid]; Why doesn't this work? */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4667 return percent;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4668 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4669
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4670 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4671 * Sets the percent bar position.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4672 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4673 * handle: Handle to the percent bar to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4674 * position: Position of the percent bar withing the range.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4675 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4676 void API dw_percent_set_pos(HWND handle, unsigned int position)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4677 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4678 DWPercent *percent = handle;
1190
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4679
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4680 /* Handle indeterminate */
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4681 if(position == DW_PERCENT_INDETERMINATE)
1193
698875cfe8e5 Fixed the indeterminate percent bar should be animated on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1190
diff changeset
4682 {
1190
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4683 [percent setIndeterminate:YES];
1193
698875cfe8e5 Fixed the indeterminate percent bar should be animated on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1190
diff changeset
4684 [percent startAnimation:percent];
698875cfe8e5 Fixed the indeterminate percent bar should be animated on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1190
diff changeset
4685 }
1190
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4686 else
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4687 {
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4688 /* Handle normal */
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4689 if([percent isIndeterminate])
1193
698875cfe8e5 Fixed the indeterminate percent bar should be animated on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1190
diff changeset
4690 {
698875cfe8e5 Fixed the indeterminate percent bar should be animated on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1190
diff changeset
4691 [percent stopAnimation:percent];
1190
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4692 [percent setIndeterminate:NO];
1193
698875cfe8e5 Fixed the indeterminate percent bar should be animated on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1190
diff changeset
4693 }
1190
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4694 [percent setDoubleValue:(double)position];
76262040ed5f Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1176
diff changeset
4695 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4696 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4697
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4698 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4699 * Create a new checkbox window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4700 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4701 * text: The text to be display by the static text widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4702 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4703 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4704 HWND API dw_checkbox_new(char *text, ULONG cid)
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4705 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4706 DWButton *button = _button_new(text, cid);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4707 [button setButtonType:NSSwitchButton];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4708 [button setBezelStyle:NSRegularSquareBezelStyle];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4709 return button;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4710 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4711
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4712 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4713 * Returns the state of the checkbox.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4714 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4715 * handle: Handle to the checkbox to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4716 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4717 int API dw_checkbox_get(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4718 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4719 DWButton *button = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4720 if([button state])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4721 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4722 return TRUE;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4723 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4724 return FALSE;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4725 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4726
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4727 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4728 * Sets the state of the checkbox.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4729 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4730 * handle: Handle to the checkbox to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4731 * value: TRUE for checked, FALSE for unchecked.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4732 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4733 void API dw_checkbox_set(HWND handle, int value)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4734 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4735 DWButton *button = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4736 if(value)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4737 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4738 [button setState:NSOnState];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4739 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4740 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4741 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4742 [button setState:NSOffState];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4743 }
656
6c8b95ca877b Comboboxes implemented.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 655
diff changeset
4744
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4745 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4746
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
4747 /* Common code for containers and listboxes */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4748 HWND _cont_new(ULONG cid, int multi)
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
4749 {
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4750 NSScrollView *scrollview = [[NSScrollView alloc] init];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4751 DWContainer *cont = [[DWContainer alloc] init];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4752
668
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
4753 [cont setScrollview:scrollview];
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
4754 [scrollview setBorderType:NSBezelBorder];
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
4755 [scrollview setHasVerticalScroller:YES];
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
4756 [scrollview setAutohidesScrollers:YES];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4757
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4758 if(multi)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4759 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4760 [cont setAllowsMultipleSelection:YES];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4761 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4762 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4763 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4764 [cont setAllowsMultipleSelection:NO];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4765 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4766 [cont setDataSource:cont];
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
4767 [cont setDelegate:cont];
668
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
4768 [scrollview setDocumentView:cont];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4769 [cont setTag:cid];
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
4770 [cont autorelease];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4771 return cont;
658
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
4772 }
0502e5b6743b Haven't finished but the basics of the container/listbox are now working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 657
diff changeset
4773
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4774 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4775 * Create a new listbox window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4776 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4777 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4778 * multi: Multiple select TRUE or FALSE.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4779 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4780 HWND API dw_listbox_new(ULONG cid, int multi)
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
4781 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4782 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4783 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4784 DWContainer *cont = _cont_new(cid, multi);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4785 [cont setHeaderView:nil];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4786 int type = DW_CFA_STRING;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4787 [cont setup];
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
4788 NSTableColumn *column = [[[NSTableColumn alloc] init] autorelease];
795
f23cad02cfb3 Make listbox, container and tree cells uneditable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 794
diff changeset
4789 [column setEditable:NO];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4790 [cont addTableColumn:column];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4791 [cont addColumn:column andType:type];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4792 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4793 return cont;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4794 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4795
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4796 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4797 * Appends the specified text to the listbox's (or combobox) entry list.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4798 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4799 * handle: Handle to the listbox to be appended to.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4800 * text: Text to append into listbox.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4801 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4802 void API dw_listbox_append(HWND handle, char *text)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4803 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4804 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4805 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4806 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4807
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4808 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4809 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4810 DWComboBox *combo = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4811
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4812 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text ]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4813 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4814 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4815 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4816 DWContainer *cont = handle;
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4817 NSString *nstr = [ NSString stringWithUTF8String:text ];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4818 NSArray *newrow = [NSArray arrayWithObject:nstr];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4819
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4820 [cont addRow:newrow];
688
b52f1d4a60dd Fixes for timers not working properly. Includes commented out test container code for threadsafety.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 687
diff changeset
4821 /*[cont performSelectorOnMainThread:@selector(addRow:)
b52f1d4a60dd Fixes for timers not working properly. Includes commented out test container code for threadsafety.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 687
diff changeset
4822 withObject:newrow
b52f1d4a60dd Fixes for timers not working properly. Includes commented out test container code for threadsafety.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 687
diff changeset
4823 waitUntilDone:YES];*/
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
4824 [cont reloadData];
794
e9bc14c5c72d Test fix for containers (and probably listboxes) not showing their content changes immediately.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 793
diff changeset
4825 [cont setNeedsDisplay:YES];
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4826 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4827 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4828 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4829
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4830 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4831 * Inserts the specified text into the listbox's (or combobox) entry list.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4832 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4833 * handle: Handle to the listbox to be inserted into.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4834 * text: Text to insert into listbox.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4835 * pos: 0-based position to insert text
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4836 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4837 void API dw_listbox_insert(HWND handle, char *text, int pos)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4838 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4839 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4840 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4841 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4842
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4843 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4844 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4845 DWComboBox *combo = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4846
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4847 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:text ] atIndex:pos];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4848 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4849 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4850 {
687
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
4851 DWContainer *cont = handle;
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
4852 NSString *nstr = [ NSString stringWithUTF8String:text ];
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
4853 NSArray *newrow = [NSArray arrayWithObject:nstr];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4854
687
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
4855 [cont insertRow:newrow at:pos];
5dde8d34bc69 Implemented dw_listbox_insert for containers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 686
diff changeset
4856 [cont reloadData];
794
e9bc14c5c72d Test fix for containers (and probably listboxes) not showing their content changes immediately.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 793
diff changeset
4857 [cont setNeedsDisplay:YES];
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4858 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4859 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4860 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4861
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4862 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4863 * Appends the specified text items to the listbox's (or combobox) entry list.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4864 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4865 * handle: Handle to the listbox to be appended to.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4866 * text: Text strings to append into listbox.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4867 * count: Number of text strings to append
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4868 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4869 void API dw_listbox_list_append(HWND handle, char **text, int count)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4870 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4871 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4872 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4873 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4874
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4875 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4876 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4877 DWComboBox *combo = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4878 int z;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4879
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4880 for(z=0;z<count;z++)
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4881 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4882 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text[z] ]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4883 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4884 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4885 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4886 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4887 DWContainer *cont = handle;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4888 int z;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4889
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4890 for(z=0;z<count;z++)
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4891 {
1318
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
4892 NSString *nstr = [NSString stringWithUTF8String:text[z]];
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
4893 NSArray *newrow = [NSArray arrayWithObjects:nstr,nil];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4894
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4895 [cont addRow:newrow];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4896 }
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
4897 [cont reloadData];
794
e9bc14c5c72d Test fix for containers (and probably listboxes) not showing their content changes immediately.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 793
diff changeset
4898 [cont setNeedsDisplay:YES];
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4899 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4900 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4901 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4902
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4903 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4904 * Clears the listbox's (or combobox) list of all entries.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4905 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4906 * handle: Handle to the listbox to be cleared.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4907 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4908 void API dw_listbox_clear(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4909 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4910 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4911 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4912 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4913
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4914 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4915 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4916 DWComboBox *combo = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4917
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4918 [combo removeAllItems];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4919 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4920 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4921 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4922 DWContainer *cont = handle;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4923
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4924 [cont clear];
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
4925 [cont reloadData];
794
e9bc14c5c72d Test fix for containers (and probably listboxes) not showing their content changes immediately.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 793
diff changeset
4926 [cont setNeedsDisplay:YES];
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4927 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4928 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4929 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4930
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4931 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4932 * Returns the listbox's item count.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4933 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4934 * handle: Handle to the listbox to be cleared.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4935 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4936 int API dw_listbox_count(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4937 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4938 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4939
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4940 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4941 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4942 DWComboBox *combo = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4943
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4944 return (int)[combo numberOfItems];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4945 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4946 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4947 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4948 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4949 DW_MUTEX_LOCK;
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4950 DWContainer *cont = handle;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4951 int result = (int)[cont numberOfRowsInTableView:cont];
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4952 DW_MUTEX_UNLOCK;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4953 return result;
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4954 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4955 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4956 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4957
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4958 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4959 * Sets the topmost item in the viewport.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4960 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4961 * handle: Handle to the listbox to be cleared.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4962 * top: Index to the top item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4963 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4964 void API dw_listbox_set_top(HWND handle, int top)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4965 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4966 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4967 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4968 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4969
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4970 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4971 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4972 DWComboBox *combo = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4973
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4974 [combo scrollItemAtIndexToTop:top];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4975 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4976 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4977 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4978 DWContainer *cont = handle;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
4979
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4980 [cont scrollRowToVisible:top];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
4981 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4982 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4983 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4984
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4985 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4986 * Copies the given index item's text into buffer.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4987 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4988 * handle: Handle to the listbox to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4989 * index: Index into the list to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4990 * buffer: Buffer where text will be copied.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4991 * length: Length of the buffer (including NULL).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4992 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4993 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4994 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4995 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
4996 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4997 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
4998
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
4999 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5000 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5001 DWComboBox *combo = handle;
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5002 int count = (int)[combo numberOfItems];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5003
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5004 if(index > count)
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5005 {
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5006 *buffer = '\0';
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5007 }
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5008 else
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5009 {
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5010 NSString *nstr = [combo itemObjectValueAtIndex:index];
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5011 strncpy(buffer, [ nstr UTF8String ], length - 1);
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5012 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5013 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5014 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5015 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5016 DWContainer *cont = handle;
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5017 int count = (int)[cont numberOfRowsInTableView:cont];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5018
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5019 if(index > count)
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5020 {
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5021 *buffer = '\0';
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5022 }
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5023 else
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5024 {
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5025 NSString *nstr = [cont getRow:index and:0];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5026
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5027 strncpy(buffer, [ nstr UTF8String ], length - 1);
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5028 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5029 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5030 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5031 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5032
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5033 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5034 * Sets the text of a given listbox entry.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5035 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5036 * handle: Handle to the listbox to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5037 * index: Index into the list to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5038 * buffer: Buffer where text will be copied.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5039 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5040 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5041 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5042 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5043 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5044 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5045
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5046 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5047 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5048 DWComboBox *combo = handle;
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5049 int count = (int)[combo numberOfItems];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5050
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5051 if(index <= count)
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5052 {
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5053 [combo removeItemAtIndex:index];
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5054 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index];
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5055 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5056 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5057 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5058 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5059 DWContainer *cont = handle;
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5060 int count = (int)[cont numberOfRowsInTableView:cont];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5061
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5062 if(index <= count)
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5063 {
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5064 NSString *nstr = [ NSString stringWithUTF8String:buffer ];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5065
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5066 [cont editCell:nstr at:index and:0];
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5067 [cont reloadData];
794
e9bc14c5c72d Test fix for containers (and probably listboxes) not showing their content changes immediately.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 793
diff changeset
5068 [cont setNeedsDisplay:YES];
720
357b59e57a31 Some fixes for out of range parameters passed to dw_listbox_g/set_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 719
diff changeset
5069 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5070 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5071 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5072 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5073
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5074 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5075 * Returns the index to the item in the list currently selected.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5076 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5077 * handle: Handle to the listbox to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5078 */
986
87dc0f5f96d0 Fix return type of dw_listbox_selected() to be "int" instead of "unsigned int" to allow -1 return.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 983
diff changeset
5079 int API dw_listbox_selected(HWND handle)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5080 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5081 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5082
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5083 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5084 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5085 DWComboBox *combo = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5086 return (int)[combo indexOfSelectedItem];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5087 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5088 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5089 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5090 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5091 DW_MUTEX_LOCK;
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5092 DWContainer *cont = handle;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5093 int result = (int)[cont selectedRow];
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5094 DW_MUTEX_UNLOCK;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5095 return result;
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5096 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5097 return -1;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5098 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5099
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5100 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5101 * Returns the index to the current selected item or -1 when done.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5102 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5103 * handle: Handle to the listbox to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5104 * where: Either the previous return or -1 to restart.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5105 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5106 int API dw_listbox_selected_multi(HWND handle, int where)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5107 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5108 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5109 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5110 id object = handle;
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5111 int retval = -1;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5112
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5113 if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5114 {
981
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
5115 NSUInteger result;
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5116 DWContainer *cont = handle;
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5117 NSIndexSet *selected = [cont selectedRowIndexes];
981
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
5118 if( where == -1 )
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
5119 result = [selected indexGreaterThanOrEqualToIndex:0];
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
5120 else
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
5121 result = [selected indexGreaterThanIndex:where];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5122
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5123 if(result != NSNotFound)
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5124 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5125 retval = (int)result;
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5126 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5127 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5128 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5129 return retval;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5130 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5131
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5132 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5133 * Sets the selection state of a given index.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5134 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5135 * handle: Handle to the listbox to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5136 * index: Item index.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5137 * state: TRUE if selected FALSE if unselected.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5138 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5139 void API dw_listbox_select(HWND handle, int index, int state)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5140 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5141 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5142 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5143 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5144
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5145 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5146 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5147 DWComboBox *combo = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5148 if(state)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5149 [combo selectItemAtIndex:index];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5150 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5151 [combo deselectItemAtIndex:index];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5152 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5153 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5154 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5155 DWContainer *cont = handle;
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5156 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)index];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5157
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5158 [cont selectRowIndexes:selected byExtendingSelection:YES];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5159 [selected release];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5160 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5161 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5162 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5163
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5164 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5165 * Deletes the item with given index from the list.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5166 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5167 * handle: Handle to the listbox to be set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5168 * index: Item index.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5169 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5170 void API dw_listbox_delete(HWND handle, int index)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5171 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5172 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5173 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5174 id object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5175
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5176 if([object isMemberOfClass:[DWComboBox class]])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5177 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5178 DWComboBox *combo = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5179
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5180 [combo removeItemAtIndex:index];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5181 }
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5182 else if([object isMemberOfClass:[DWContainer class]])
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5183 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5184 DWContainer *cont = handle;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5185
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5186 [cont removeRow:index];
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
5187 [cont reloadData];
794
e9bc14c5c72d Test fix for containers (and probably listboxes) not showing their content changes immediately.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 793
diff changeset
5188 [cont setNeedsDisplay:YES];
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
5189 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5190 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5191 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5192
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5193 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5194 * Create a new Combobox window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5195 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5196 * text: The default text to be in the combpbox widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5197 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5198 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5199 HWND API dw_combobox_new(char *text, ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5200 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5201 DWComboBox *combo = [[DWComboBox alloc] init];
804
5b4a831af8fa Fix for dw_combobox_new() not setting the default text in the entryfield.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 803
diff changeset
5202 [combo setStringValue:[NSString stringWithUTF8String:text]];
703
329736825f9b Implemented more of the missing event/signal handlers and other code cleanups.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 702
diff changeset
5203 [combo setDelegate:combo];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5204 [combo setTag:cid];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5205 return combo;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5206 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5207
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5208 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5209 * Create a new Multiline Editbox window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5210 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5211 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5212 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5213 HWND API dw_mle_new(ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5214 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5215 DWMLE *mle = [[DWMLE alloc] init];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
5216 NSScrollView *scrollview = [[NSScrollView alloc] init];
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5217 NSSize size = [mle maxSize];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5218
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5219 size.width = size.height;
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5220 [mle setMaxSize:size];
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
5221 [scrollview setBorderType:NSBezelBorder];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
5222 [scrollview setHasVerticalScroller:YES];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
5223 [scrollview setAutohidesScrollers:YES];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
5224 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
5225 [scrollview setDocumentView:mle];
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5226 [mle setVerticallyResizable:YES];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5227 [mle setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5228 [mle setScrollview:scrollview];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5229 /* [mle setTag:cid]; Why doesn't this work? */
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
5230 [mle autorelease];
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5231 return mle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5232 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5233
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5234 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5235 * Adds text to an MLE box and returns the current point.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5236 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5237 * handle: Handle to the MLE to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5238 * buffer: Text buffer to be imported.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5239 * startpoint: Point to start entering text.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5240 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5241 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5242 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5243 DWMLE *mle = handle;
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5244 int _locked_by_me = FALSE;
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5245 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5246 NSTextStorage *ts = [mle textStorage];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5247 NSString *nstr = [NSString stringWithUTF8String:buffer];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5248 NSMutableString *ms = [ts mutableString];
992
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5249 NSUInteger length = [ms length];
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5250 if(startpoint < 0)
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5251 startpoint = 0;
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5252 if(startpoint > length)
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5253 startpoint = (int)length;
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5254 [ms insertString:nstr atIndex:startpoint];
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5255 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5256 return (unsigned int)strlen(buffer) + startpoint;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5257 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5258
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5259 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5260 * Grabs text from an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5261 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5262 * handle: Handle to the MLE to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5263 * buffer: Text buffer to be exported.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5264 * startpoint: Point to start grabbing text.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5265 * length: Amount of text to be grabbed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5266 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5267 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5268 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5269 DWMLE *mle = handle;
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5270 int _locked_by_me = FALSE;
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5271 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5272 NSTextStorage *ts = [mle textStorage];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5273 NSMutableString *ms = [ts mutableString];
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
5274 const char *tmp = [ms UTF8String];
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
5275 strncpy(buffer, tmp+startpoint, length);
1129
ab73d0269a5b Ensure default keypress event is not processed if handler returns 1
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1128
diff changeset
5276 buffer[length] = '\0';
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5277 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5278 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5279
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5280 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5281 * Obtains information about an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5282 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5283 * handle: Handle to the MLE to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5284 * bytes: A pointer to a variable to return the total bytes.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5285 * lines: A pointer to a variable to return the number of lines.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5286 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5287 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5288 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5289 DWMLE *mle = handle;
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5290 int _locked_by_me = FALSE;
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5291 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5292 NSTextStorage *ts = [mle textStorage];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5293 NSMutableString *ms = [ts mutableString];
807
f7016a38bedd Fix for dw_window_set_text() on buttons not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 806
diff changeset
5294 NSUInteger numberOfLines, index, stringLength = [ms length];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5295
992
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5296 if(bytes)
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5297 *bytes = stringLength;
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5298 if(lines)
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5299 {
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5300 for(index=0, numberOfLines=0; index < stringLength; numberOfLines++)
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5301 index = NSMaxRange([ms lineRangeForRange:NSMakeRange(index, 0)]);
1041
6a57bf20d8f9 Return displayName property instead of fontName property in dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1040
diff changeset
5302
992
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5303 *lines = numberOfLines;
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5304 }
1819
d784b85b632e Change incorrect call to DW_MUTEX_LOCK to DW_MUTEX_UNLOCK in dw_mle_get_size()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1809
diff changeset
5305 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5306 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5307
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5308 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5309 * Deletes text from an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5310 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5311 * handle: Handle to the MLE to be deleted from.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5312 * startpoint: Point to start deleting text.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5313 * length: Amount of text to be deleted.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5314 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5315 void API dw_mle_delete(HWND handle, int startpoint, int length)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5316 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5317 DWMLE *mle = handle;
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5318 int _locked_by_me = FALSE;
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5319 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5320 NSTextStorage *ts = [mle textStorage];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5321 NSMutableString *ms = [ts mutableString];
992
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5322 NSUInteger mslength = [ms length];
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5323 if(startpoint < 0)
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5324 startpoint = 0;
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5325 if(startpoint > mslength)
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5326 startpoint = (int)mslength;
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5327 if(startpoint + length > mslength)
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5328 length = (int)mslength - startpoint;
2d80b4dcff9a A few MLE fixes on the Mac... and a slightly updated dwtest for MLE testing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 989
diff changeset
5329 [ms deleteCharactersInRange:NSMakeRange(startpoint, length)];
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5330 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5331 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5332
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5333 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5334 * Clears all text from an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5335 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5336 * handle: Handle to the MLE to be cleared.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5337 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5338 void API dw_mle_clear(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5339 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5340 DWMLE *mle = handle;
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5341 int _locked_by_me = FALSE;
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5342 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5343 NSTextStorage *ts = [mle textStorage];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5344 NSMutableString *ms = [ts mutableString];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5345 NSUInteger length = [ms length];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5346 [ms deleteCharactersInRange:NSMakeRange(0, length)];
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5347 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5348 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5349
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5350 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5351 * Sets the visible line of an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5352 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5353 * handle: Handle to the MLE to be positioned.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5354 * line: Line to be visible.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5355 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5356 void API dw_mle_set_visible(HWND handle, int line)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5357 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5358 DWMLE *mle = handle;
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5359 int _locked_by_me = FALSE;
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5360 DW_MUTEX_LOCK;
802
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5361 NSTextStorage *ts = [mle textStorage];
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5362 NSMutableString *ms = [ts mutableString];
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5363 NSUInteger numberOfLines, index, stringLength = [ms length];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5364
802
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5365 for(index=0, numberOfLines=0; index < stringLength && numberOfLines < line; numberOfLines++)
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5366 index = NSMaxRange([ms lineRangeForRange:NSMakeRange(index, 0)]);
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5367
802
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5368 if(line == numberOfLines)
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5369 {
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5370 [mle scrollRangeToVisible:[ms lineRangeForRange:NSMakeRange(index, 0)]];
676d46b31a11 Initial implementation of dw_mle_set_visible().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 801
diff changeset
5371 }
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5372 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5373 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5374
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5375 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5376 * Sets the editablity of an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5377 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5378 * handle: Handle to the MLE.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5379 * state: TRUE if it can be edited, FALSE for readonly.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5380 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5381 void API dw_mle_set_editable(HWND handle, int state)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5382 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5383 DWMLE *mle = handle;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5384 if(state)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5385 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5386 [mle setEditable:YES];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5387 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5388 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5389 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5390 [mle setEditable:NO];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5391 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5392 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5393
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5394 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5395 * Sets the word wrap state of an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5396 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5397 * handle: Handle to the MLE.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5398 * state: TRUE if it wraps, FALSE if it doesn't.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5399 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5400 void API dw_mle_set_word_wrap(HWND handle, int state)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5401 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5402 DWMLE *mle = handle;
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5403 NSScrollView *sv = [mle scrollview];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
5404
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5405 if(state)
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5406 {
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5407 [[mle textContainer] setWidthTracksTextView:YES];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5408 [sv setHasHorizontalScroller:NO];
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5409 }
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5410 else
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5411 {
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5412 [[mle textContainer] setWidthTracksTextView:NO];
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5413 [[mle textContainer] setContainerSize:[mle maxSize]];
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5414 [mle setHorizontallyResizable:YES];
1551
cf897886ceeb Fixed disabling word wrap in the MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1549
diff changeset
5415 [sv setHasHorizontalScroller:YES];
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
5416 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5417 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5418
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5419 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5420 * Sets the current cursor position of an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5421 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5422 * handle: Handle to the MLE to be positioned.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5423 * point: Point to position cursor.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5424 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5425 void API dw_mle_set_cursor(HWND handle, int point)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5426 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5427 DWMLE *mle = handle;
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5428 int _locked_by_me = FALSE;
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5429 DW_MUTEX_LOCK;
989
6de00477d627 Clamp the point specified in dw_mle_set_cursor() to the range of text to avoid an exception on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 986
diff changeset
5430 NSTextStorage *ts = [mle textStorage];
6de00477d627 Clamp the point specified in dw_mle_set_cursor() to the range of text to avoid an exception on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 986
diff changeset
5431 NSMutableString *ms = [ts mutableString];
6de00477d627 Clamp the point specified in dw_mle_set_cursor() to the range of text to avoid an exception on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 986
diff changeset
5432 NSUInteger length = [ms length];
6de00477d627 Clamp the point specified in dw_mle_set_cursor() to the range of text to avoid an exception on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 986
diff changeset
5433 if(point < 0)
6de00477d627 Clamp the point specified in dw_mle_set_cursor() to the range of text to avoid an exception on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 986
diff changeset
5434 point = 0;
6de00477d627 Clamp the point specified in dw_mle_set_cursor() to the range of text to avoid an exception on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 986
diff changeset
5435 if(point > length)
6de00477d627 Clamp the point specified in dw_mle_set_cursor() to the range of text to avoid an exception on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 986
diff changeset
5436 point = (int)length;
712
01107d8e033e Fixed the scrollbar maximum range to be correct. Also added some MLE code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 711
diff changeset
5437 [mle setSelectedRange: NSMakeRange(point,point)];
1201
196cd8a8e6a8 Fixed dw_mle_set_cursor() should scroll to the point on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1193
diff changeset
5438 [mle scrollRangeToVisible:NSMakeRange(point,point)];
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5439 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5440 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5441
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5442 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5443 * Finds text in an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5444 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5445 * handle: Handle to the MLE to be cleared.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5446 * text: Text to search for.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5447 * point: Start point of search.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5448 * flags: Search specific flags.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5449 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5450 int API dw_mle_search(HWND handle, char *text, int point, unsigned long flags)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5451 {
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
5452 DWMLE *mle = handle;
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5453 int _locked_by_me = FALSE;
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5454 DW_MUTEX_LOCK;
888
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5455 NSTextStorage *ts = [mle textStorage];
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5456 NSMutableString *ms = [ts mutableString];
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5457 NSString *searchForMe = [NSString stringWithUTF8String:text];
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5458 NSRange searchRange = NSMakeRange(point, [ms length] - point);
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5459 NSRange range = NSMakeRange(NSNotFound, 0);
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5460 NSUInteger options = flags ? flags : NSCaseInsensitiveSearch;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5461
888
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5462 if(ms)
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5463 {
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5464 range = [ms rangeOfString:searchForMe options:options range:searchRange];
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5465 }
1204
5cb7e52f76c7 Put Mac MLE under mutex protection because of crashes when accessing the MLE from threads.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1202
diff changeset
5466 DW_MUTEX_UNLOCK;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5467 if(range.location != NSNotFound)
888
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5468 {
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5469 return -1;
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5470 }
cd6ff038e38b Implemented dw_mle_search on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 887
diff changeset
5471 return (int)range.location;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5472 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5473
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5474 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5475 * Stops redrawing of an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5476 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5477 * handle: Handle to the MLE to freeze.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5478 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5479 void API dw_mle_freeze(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5480 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5481 /* Don't think this is necessary */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5482 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5483
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5484 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5485 * Resumes redrawing of an MLE box.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5486 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5487 * handle: Handle to the MLE to thaw.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5488 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5489 void API dw_mle_thaw(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5490 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5491 /* Don't think this is necessary */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5492 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5493
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5494 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5495 * Create a new status text window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5496 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5497 * text: The text to be display by the static text widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5498 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5499 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5500 HWND API dw_status_text_new(char *text, ULONG cid)
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5501 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
5502 NSBox *border = [[NSBox alloc] init];
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
5503 NSTextField *textfield = dw_text_new(text, cid);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
5504
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
5505 [border setBorderType:NSGrooveBorder];
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
5506 //[border setBorderType:NSLineBorder];
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
5507 [border setTitlePosition:NSNoTitle];
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
5508 [border setContentView:textfield];
1778
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
5509 [border setContentViewMargins:NSMakeSize(1.5,1.5)];
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
5510 [textfield autorelease];
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
5511 [textfield setBackgroundColor:[NSColor clearColor]];
931
dfd84cefd80b Minor changes to vertical centering on (status) text fields on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 930
diff changeset
5512 [[textfield cell] setVCenter:YES];
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
5513 return border;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5514 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5515
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5516 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5517 * Create a new static text window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5518 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5519 * text: The text to be display by the static text widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5520 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5521 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5522 HWND API dw_text_new(char *text, ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5523 {
1564
d84a690448c3 Attempted fix at border calculation on Mac for status text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1559
diff changeset
5524 DWText *textfield = [[DWText alloc] init];
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5525 [textfield setEditable:NO];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5526 [textfield setSelectable:NO];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5527 [textfield setBordered:NO];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5528 [textfield setDrawsBackground:NO];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5529 [textfield setStringValue:[ NSString stringWithUTF8String:text ]];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5530 [textfield setTag:cid];
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5531 if(DWDefaultFont)
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5532 {
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5533 [[textfield cell] setFont:DWDefaultFont];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5534 }
1712
daa59fc8d6e5 Disable wrapping on entryfields and static text on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1709
diff changeset
5535 [[textfield cell] setWraps:NO];
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
5536 return textfield;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5537 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5538
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5539 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5540 * Creates a rendering context widget (window) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5541 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5542 * id: An id to be used with dw_window_from_id.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5543 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5544 * A handle to the widget or NULL on failure.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5545 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
5546 HWND API dw_render_new(unsigned long cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5547 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5548 DWRender *render = [[DWRender alloc] init];
922
07f9a73c6847 Fix for button press/release events coordinates being relative to the window instead of the screen on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 921
diff changeset
5549 [render setTag:cid];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5550 return render;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5551 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5552
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5553 /* Sets the current foreground drawing color.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5554 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5555 * red: red value.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5556 * green: green value.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5557 * blue: blue value.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5558 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5559 void API dw_color_foreground_set(unsigned long value)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5560 {
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5561 NSColor *oldcolor = pthread_getspecific(_dw_fg_color_key);
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5562 NSColor *newcolor;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5563 DW_LOCAL_POOL_IN;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5564
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5565 _foreground = _get_color(value);
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5566
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5567 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green:
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5568 DW_GREEN_VALUE(_foreground)/255.0 blue:
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5569 DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] retain];
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5570 pthread_setspecific(_dw_fg_color_key, newcolor);
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5571 [oldcolor release];
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5572 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5573 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5574
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5575 /* Sets the current background drawing color.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5576 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5577 * red: red value.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5578 * green: green value.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5579 * blue: blue value.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5580 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5581 void API dw_color_background_set(unsigned long value)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5582 {
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5583 NSColor *oldcolor = pthread_getspecific(_dw_bg_color_key);
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5584 NSColor *newcolor;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5585 DW_LOCAL_POOL_IN;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5586
891
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5587 if(value == DW_CLR_DEFAULT)
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5588 {
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5589 pthread_setspecific(_dw_bg_color_key, NULL);
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5590 }
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5591 else
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5592 {
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5593 _background = _get_color(value);
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5594
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5595 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_background)/255.0 green:
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5596 DW_GREEN_VALUE(_background)/255.0 blue:
891
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5597 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain];
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5598 pthread_setspecific(_dw_bg_color_key, newcolor);
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5599 }
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5600 [oldcolor release];
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5601 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5602 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5603
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5604 /* Allows the user to choose a color using the system's color chooser dialog.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5605 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5606 * value: current color
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5607 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5608 * The selected color or the current color if cancelled.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5609 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5610 unsigned long API dw_color_choose(unsigned long value)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5611 {
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5612 /* Create the Color Chooser Dialog class. */
1644
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5613 DWColorChoose *colorDlg;
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5614 DWDialog *dialog;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
5615 DW_LOCAL_POOL_IN;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5616
1644
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5617 if(![DWColorChoose sharedColorPanelExists])
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5618 {
733
8d5e5b89725f Fixed the crashing issue with dw_color_choose() it now functions properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 732
diff changeset
5619 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel];
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5620 /* Set defaults for the dialog. */
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5621 [colorDlg setContinuous:NO];
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5622 [colorDlg setTarget:colorDlg];
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5623 [colorDlg setAction:@selector(changeColor:)];
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5624 }
1644
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5625 else
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5626 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
5627
1644
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5628 /* If someone is already waiting just return */
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5629 if([colorDlg dialog])
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5630 {
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5631 DW_LOCAL_POOL_OUT;
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5632 return value;
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5633 }
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5634
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5635 unsigned long tempcol = _get_color(value);
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5636 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(tempcol)/255.0 green: DW_GREEN_VALUE(tempcol)/255.0 blue: DW_BLUE_VALUE(tempcol)/255.0 alpha: 1] retain];
2b55465887e1 Color chooser changes for Lion compatibility on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1610
diff changeset
5637 [colorDlg setColor:color];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
5638
733
8d5e5b89725f Fixed the crashing issue with dw_color_choose() it now functions properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 732
diff changeset
5639 dialog = dw_dialog_new(colorDlg);
8d5e5b89725f Fixed the crashing issue with dw_color_choose() it now functions properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 732
diff changeset
5640 [colorDlg setDialog:dialog];
690
b93f5cdab37d Fixes to the color picker... it actually shows the picker now but it still needs more work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 689
diff changeset
5641 [colorDlg makeKeyAndOrderFront:nil];
733
8d5e5b89725f Fixed the crashing issue with dw_color_choose() it now functions properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 732
diff changeset
5642
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5643 /* Wait for them to pick a color */
690
b93f5cdab37d Fixes to the color picker... it actually shows the picker now but it still needs more work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 689
diff changeset
5644 color = (NSColor *)dw_dialog_wait(dialog);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5645
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5646 /* Figure out the value of what they returned */
734
668a88a0b930 Fixed a minor 64/32 bit issue and fixed my having blue and red values reversed in the color table.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 733
diff changeset
5647 CGFloat red, green, blue;
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5648 [color getRed:&red green:&green blue:&blue alpha:NULL];
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5649 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255));
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
5650 DW_LOCAL_POOL_OUT;
732
db3a173e487e Fixes for the color chooser... it now works a single time. However...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 731
diff changeset
5651 return value;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5652 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5653
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5654 /* Draw a point on a window (preferably a render window).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5655 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5656 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5657 * pixmap: Handle to the pixmap. (choose only one of these)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5658 * x: X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5659 * y: Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5660 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5661 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5662 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5663 int _locked_by_me = FALSE;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5664 DW_LOCAL_POOL_IN;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5665 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5666 id image = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5667 if(pixmap)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5668 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5669 image = (id)pixmap->image;
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5670 [NSGraphicsContext saveGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5671 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5672 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5673 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5674 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5675 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5676 if([image lockFocusIfCanDraw] == NO)
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5677 {
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5678 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5679 DW_LOCAL_POOL_OUT;
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5680 return;
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5681 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5682 _DWLastDrawable = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5683 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5684 NSBezierPath* aPath = [NSBezierPath bezierPath];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5685 [aPath setLineWidth: 0.5];
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5686 NSColor *color = pthread_getspecific(_dw_fg_color_key);
665
e6bec2290f3f Fixing warnings with Xcode 4 and switched to manual releasing in the draw functions to stop leaking.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 664
diff changeset
5687 [color set];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5688
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5689 [aPath moveToPoint:NSMakePoint(x, y)];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5690 [aPath stroke];
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5691 if(pixmap)
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5692 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5693 [NSGraphicsContext restoreGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5694 }
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5695 else
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5696 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5697 [image unlockFocus];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5698 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5699 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5700 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5701 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5702
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5703 /* Draw a line on a window (preferably a render window).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5704 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5705 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5706 * pixmap: Handle to the pixmap. (choose only one of these)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5707 * x1: First X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5708 * y1: First Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5709 * x2: Second X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5710 * y2: Second Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5711 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5712 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5713 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5714 int _locked_by_me = FALSE;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5715 DW_LOCAL_POOL_IN;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5716 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5717 id image = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5718 if(pixmap)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5719 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5720 image = (id)pixmap->image;
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5721 [NSGraphicsContext saveGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5722 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5723 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5724 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5725 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5726 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5727 if([image lockFocusIfCanDraw] == NO)
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5728 {
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5729 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5730 DW_LOCAL_POOL_OUT;
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5731 return;
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5732 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5733 _DWLastDrawable = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5734 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5735 NSBezierPath* aPath = [NSBezierPath bezierPath];
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5736 NSColor *color = pthread_getspecific(_dw_fg_color_key);
665
e6bec2290f3f Fixing warnings with Xcode 4 and switched to manual releasing in the draw functions to stop leaking.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 664
diff changeset
5737 [color set];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5738
1527
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5739 [aPath moveToPoint:NSMakePoint(x1 + 0.5, y1 + 0.5)];
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5740 [aPath lineToPoint:NSMakePoint(x2 + 0.5, y2 + 0.5)];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5741 [aPath stroke];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5742
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5743 if(pixmap)
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5744 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5745 [NSGraphicsContext restoreGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5746 }
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5747 else
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5748 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5749 [image unlockFocus];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5750 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5751 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5752 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5753 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5754
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5755 /* Draw text on a window (preferably a render window).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5756 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5757 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5758 * pixmap: Handle to the pixmap. (choose only one of these)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5759 * x: X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5760 * y: Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5761 * text: Text to be displayed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5762 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5763 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5764 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5765 int _locked_by_me = FALSE;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5766 DW_LOCAL_POOL_IN;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5767 DW_MUTEX_LOCK;
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5768 id image = handle;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5769 NSString *nstr = [ NSString stringWithUTF8String:text ];
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5770 if(image)
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5771 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5772 if([image isMemberOfClass:[DWRender class]])
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5773 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5774 DWRender *render = handle;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5775 NSFont *font = [render font];
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5776 if([image lockFocusIfCanDraw] == NO)
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5777 {
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5778 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5779 DW_LOCAL_POOL_OUT;
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5780 return;
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5781 }
891
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5782 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key);
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5783 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key);
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5784 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil];
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5785 if(bgcolor)
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5786 {
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5787 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName];
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5788 }
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5789 if(font)
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5790 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5791 [dict setValue:font forKey:NSFontAttributeName];
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5792 }
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5793 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict];
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5794 [image unlockFocus];
827
dc094750d284 Fixed leak in dw_draw_text() not releasing the dictionary which was also pulling the NSColor along.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 826
diff changeset
5795 [dict release];
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5796 }
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5797 _DWLastDrawable = handle;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5798 }
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5799 if(pixmap)
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5800 {
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
5801 NSFont *font = pixmap->font;
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5802 DWRender *render = pixmap->handle;
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
5803 if(!font && [render isMemberOfClass:[DWRender class]])
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5804 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5805 font = [render font];
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5806 }
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5807 image = (id)pixmap->image;
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5808 [NSGraphicsContext saveGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5809 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
5810 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]];
891
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5811 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key);
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5812 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key);
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5813 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil];
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5814 if(bgcolor)
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5815 {
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5816 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName];
3774af45eb0c Fix for dw_draw_text() not using the background color on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 890
diff changeset
5817 }
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5818 if(font)
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5819 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5820 [dict setValue:font forKey:NSFontAttributeName];
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5821 }
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5822 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict];
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5823 [NSGraphicsContext restoreGraphicsState];
827
dc094750d284 Fixed leak in dw_draw_text() not releasing the dictionary which was also pulling the NSColor along.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 826
diff changeset
5824 [dict release];
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5825 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5826 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5827 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5828 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5829
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5830 /* Query the width and height of a text string.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5831 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5832 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5833 * pixmap: Handle to the pixmap. (choose only one of these)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5834 * text: Text to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5835 * width: Pointer to a variable to be filled in with the width.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5836 * height Pointer to a variable to be filled in with the height.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5837 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5838 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5839 {
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5840 id object = handle;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5841 NSString *nstr;
1230
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5842 NSFont *font = nil;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5843 DW_LOCAL_POOL_IN;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
5844
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5845 nstr = [NSString stringWithUTF8String:text];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
5846
1230
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5847 /* Check the pixmap for associated object or font */
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5848 if(pixmap)
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5849 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5850 object = pixmap->handle;
1230
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5851 font = pixmap->font;
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5852 }
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5853 NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
1230
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5854 /* If we didn't get a font from the pixmap... try the associated object */
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5855 if(!font && ([object isMemberOfClass:[DWRender class]] || [object isKindOfClass:[NSControl class]]))
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5856 {
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5857 font = [object font];
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5858 }
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5859 /* If we got a font... add it to the dictionary */
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5860 if(font)
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5861 {
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5862 [dict setValue:font forKey:NSFontAttributeName];
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5863 }
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5864 /* Calculate the size of the string */
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5865 NSSize size = [nstr sizeWithAttributes:dict];
665
e6bec2290f3f Fixing warnings with Xcode 4 and switched to manual releasing in the draw functions to stop leaking.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 664
diff changeset
5866 [dict release];
1230
75a773cdb626 Fixes to dw_font_text_extents_get() on Mac so it honors the font set with dw_pixmap_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1225
diff changeset
5867 /* Return whatever information we can */
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5868 if(width)
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5869 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5870 *width = size.width;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5871 }
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5872 if(height)
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5873 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5874 *height = size.height;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
5875 }
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5876 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5877 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5878
1523
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5879 /* Internal function to create an image graphics context...
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5880 * with or without antialiasing enabled.
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5881 */
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5882 id _create_gc(id image, bool antialiased)
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5883 {
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5884 CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort];
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5885 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES];
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5886 [gc setShouldAntialias:antialiased];
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5887 CGContextSetAllowsAntialiasing(context, antialiased);
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5888 return gc;
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5889 }
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5890
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5891 /* Draw a polygon on a window (preferably a render window).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5892 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5893 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5894 * pixmap: Handle to the pixmap. (choose only one of these)
1275
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
5895 * flags: DW_DRAW_FILL (1) to fill the polygon or DW_DRAW_DEFAULT (0).
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5896 * x: X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5897 * y: Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5898 * width: Width of rectangle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5899 * height: Height of rectangle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5900 */
1275
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
5901 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y )
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5902 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5903 int _locked_by_me = FALSE;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5904 DW_LOCAL_POOL_IN;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5905 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5906 id image = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5907 int z;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5908 if(pixmap)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5909 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5910 image = (id)pixmap->image;
1523
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5911 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES);
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5912 [NSGraphicsContext saveGraphicsState];
1523
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5913 [NSGraphicsContext setCurrentContext:gc];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5914 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5915 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5916 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5917 if([image lockFocusIfCanDraw] == NO)
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5918 {
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5919 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5920 DW_LOCAL_POOL_OUT;
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5921 return;
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5922 }
1527
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5923 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5924 _DWLastDrawable = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5925 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5926 NSBezierPath* aPath = [NSBezierPath bezierPath];
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5927 NSColor *color = pthread_getspecific(_dw_fg_color_key);
665
e6bec2290f3f Fixing warnings with Xcode 4 and switched to manual releasing in the draw functions to stop leaking.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 664
diff changeset
5928 [color set];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5929
1527
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5930 [aPath moveToPoint:NSMakePoint(*x + 0.5, *y + 0.5)];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5931 for(z=1;z<npoints;z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5932 {
1527
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5933 [aPath lineToPoint:NSMakePoint(x[z] + 0.5, y[z] + 0.5)];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5934 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5935 [aPath closePath];
1275
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
5936 if(flags & DW_DRAW_FILL)
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5937 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5938 [aPath fill];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5939 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5940 [aPath stroke];
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5941 if(pixmap)
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5942 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5943 [NSGraphicsContext restoreGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5944 }
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5945 else
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5946 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5947 [image unlockFocus];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5948 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5949 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5950 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5951 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5952
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5953 /* Draw a rectangle on a window (preferably a render window).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5954 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5955 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5956 * pixmap: Handle to the pixmap. (choose only one of these)
1275
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
5957 * flags: DW_DRAW_FILL (1) to fill the box or DW_DRAW_DEFAULT (0).
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5958 * x: X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5959 * y: Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5960 * width: Width of rectangle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5961 * height: Height of rectangle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5962 */
1275
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
5963 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5964 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5965 int _locked_by_me = FALSE;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5966 DW_LOCAL_POOL_IN;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
5967 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5968 id image = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5969 if(pixmap)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5970 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5971 image = (id)pixmap->image;
1523
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5972 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES);
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5973 [NSGraphicsContext saveGraphicsState];
1523
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
5974 [NSGraphicsContext setCurrentContext:gc];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5975 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5976 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5977 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5978 if([image lockFocusIfCanDraw] == NO)
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5979 {
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5980 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
5981 DW_LOCAL_POOL_OUT;
747
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5982 return;
a4f99795ff26 Abort drawing functions if we fail to lock focus on a render control.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 745
diff changeset
5983 }
1527
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5984 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5985 _DWLastDrawable = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
5986 }
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
5987 NSColor *color = pthread_getspecific(_dw_fg_color_key);
665
e6bec2290f3f Fixing warnings with Xcode 4 and switched to manual releasing in the draw functions to stop leaking.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 664
diff changeset
5988 [color set];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
5989
1275
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
5990 if(flags & DW_DRAW_FILL)
1527
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5991 [NSBezierPath fillRect:NSMakeRect(x, y, width, height)];
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5992 else
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
5993 [NSBezierPath strokeRect:NSMakeRect(x, y, width, height)];
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5994 if(pixmap)
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5995 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5996 [NSGraphicsContext restoreGraphicsState];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5997 }
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5998 else
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
5999 {
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
6000 [image unlockFocus];
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
6001 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6002 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
6003 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6004 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6005
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6006 /* Draw an arc on a window (preferably a render window).
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6007 * Parameters:
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6008 * handle: Handle to the window.
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6009 * pixmap: Handle to the pixmap. (choose only one of these)
1275
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
6010 * flags: DW_DRAW_FILL (1) to fill the arc or DW_DRAW_DEFAULT (0).
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
6011 * DW_DRAW_FULL will draw a complete circle/elipse.
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6012 * xorigin: X coordinate of center of arc.
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6013 * yorigin: Y coordinate of center of arc.
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6014 * x1: X coordinate of first segment of arc.
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6015 * y1: Y coordinate of first segment of arc.
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6016 * x2: X coordinate of second segment of arc.
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6017 * y2: Y coordinate of second segment of arc.
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6018 */
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6019 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2)
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6020 {
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6021 int _locked_by_me = FALSE;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
6022 DW_LOCAL_POOL_IN;
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6023 DW_MUTEX_LOCK;
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6024 id image = handle;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6025
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6026 if(pixmap)
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6027 {
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6028 image = (id)pixmap->image;
1523
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
6029 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES);
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6030 [NSGraphicsContext saveGraphicsState];
1523
026c0b4d6ee9 Initial implmentation of DW_DRAW_NOAA on Mac... only works on pixmaps right now.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1522
diff changeset
6031 [NSGraphicsContext setCurrentContext:gc];
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6032 }
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6033 else
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6034 {
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6035 if([image lockFocusIfCanDraw] == NO)
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6036 {
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6037 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
6038 DW_LOCAL_POOL_OUT;
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6039 return;
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6040 }
1527
9bab702bd6c1 A bunch of Mac drawing updates to correct issues and improve performance.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1523
diff changeset
6041 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6042 _DWLastDrawable = handle;
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6043 }
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6044 NSBezierPath* aPath = [NSBezierPath bezierPath];
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6045 NSColor *color = pthread_getspecific(_dw_fg_color_key);
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6046 [color set];
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6047
1275
0b34e2cf0706 Updated dw_draw_rect and dw_draw_polygon to accept flags the same way as dw_draw_arc.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1269
diff changeset
6048 /* Special case of a full circle/oval */
1269
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6049 if(flags & DW_DRAW_FULL)
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6050 {
1279
ee9a233f1b42 Fixed DW_DRAW_FULL for arcs on Mac. Rectangle was being created incorrectly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1277
diff changeset
6051 [aPath appendBezierPathWithOvalInRect:NSMakeRect(x1, y1, x2 - x1, y2 - y1)];
1269
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6052 }
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6053 else
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6054 {
1650
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6055 double a1 = atan2((y1-yorigin), (x1-xorigin));
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6056 double a2 = atan2((y2-yorigin), (x2-xorigin));
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6057 double dx = xorigin - x1;
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6058 double dy = yorigin - y1;
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6059 double r = sqrt(dx*dx + dy*dy);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6060
1650
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6061 /* Convert to degrees */
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6062 a1 *= (180.0 / M_PI);
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6063 a2 *= (180.0 / M_PI);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6064
1269
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6065 /* Prepare to draw */
1650
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6066 [aPath appendBezierPathWithArcWithCenter:NSMakePoint(xorigin, yorigin)
1f35129e4817 Improved arc drawing on the Mac using the same method as GDI+ on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1649
diff changeset
6067 radius:r startAngle:a1 endAngle:a2];
1269
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6068 }
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6069 /* If the fill flag is passed */
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6070 if(flags & DW_DRAW_FILL)
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6071 {
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6072 [aPath fill];
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6073 }
9e477efbacca Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1264
diff changeset
6074 /* Actually do the drawing */
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6075 [aPath stroke];
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6076 if(pixmap)
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6077 {
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6078 [NSGraphicsContext restoreGraphicsState];
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6079 }
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6080 else
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6081 {
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6082 [image unlockFocus];
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6083 }
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6084 DW_MUTEX_UNLOCK;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
6085 DW_LOCAL_POOL_OUT;
1261
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6086 }
61d0c5f84644 Initial attempt at adding dw_draw_arc() support on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1247
diff changeset
6087
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6088 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6089 * Create a tree object to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6090 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6091 * id: An ID to be used for getting the resource from the
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6092 * resource file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6093 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
6094 HWND API dw_tree_new(ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6095 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6096 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6097 DW_MUTEX_LOCK;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6098 NSScrollView *scrollview = [[NSScrollView alloc] init];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6099 DWTree *tree = [[DWTree alloc] init];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6100
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6101 [tree setScrollview:scrollview];
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6102 [scrollview setBorderType:NSBezelBorder];
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6103 [scrollview setHasVerticalScroller:YES];
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6104 [scrollview setAutohidesScrollers:YES];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6105
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6106 [tree setAllowsMultipleSelection:NO];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6107 [tree setDataSource:tree];
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6108 [tree setDelegate:tree];
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6109 [scrollview setDocumentView:tree];
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6110 [tree setHeaderView:nil];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
6111 [tree setTag:cid];
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
6112 [tree autorelease];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6113 DW_MUTEX_UNLOCK;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6114 return tree;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6115 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6116
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6117 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6118 * Inserts an item into a tree window (widget) after another item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6119 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6120 * handle: Handle to the tree to be inserted.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6121 * item: Handle to the item to be positioned after.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6122 * title: The text title of the entry.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6123 * icon: Handle to coresponding icon.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6124 * parent: Parent handle or 0 if root.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6125 * itemdata: Item specific data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6126 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6127 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, HICN icon, HTREEITEM parent, void *itemdata)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6128 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6129 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6130 DW_MUTEX_LOCK;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6131 DWTree *tree = handle;
935
114729f5aedc Needed to retain NSStrings in the tree view on Mac to prevent crashes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 934
diff changeset
6132 NSString *nstr = [[NSString stringWithUTF8String:title] retain];
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6133 NSMutableArray *treenode = [[[NSMutableArray alloc] init] retain];
1067
6ca1132a240e Allow tree nodes without icons using the new NSMutableArray tree code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1065
diff changeset
6134 if(icon)
6ca1132a240e Allow tree nodes without icons using the new NSMutableArray tree code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1065
diff changeset
6135 [treenode addObject:icon];
6ca1132a240e Allow tree nodes without icons using the new NSMutableArray tree code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1065
diff changeset
6136 else
6ca1132a240e Allow tree nodes without icons using the new NSMutableArray tree code on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1065
diff changeset
6137 [treenode addObject:[NSNull null]];
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6138 [treenode addObject:nstr];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6139 [treenode addObject:[NSValue valueWithPointer:itemdata]];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6140 [treenode addObject:[NSNull null]];
1064
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
6141 [tree addTree:treenode and:parent after:item];
1063
2ebaea72ac95 Fix for some release calls causing issues on MacOS 10.7 Lion.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1061
diff changeset
6142 if(parent)
2ebaea72ac95 Fix for some release calls causing issues on MacOS 10.7 Lion.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1061
diff changeset
6143 [tree reloadItem:parent reloadChildren:YES];
2ebaea72ac95 Fix for some release calls causing issues on MacOS 10.7 Lion.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1061
diff changeset
6144 else
2ebaea72ac95 Fix for some release calls causing issues on MacOS 10.7 Lion.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1061
diff changeset
6145 [tree reloadData];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6146 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6147 return treenode;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6148 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6149
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6150 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6151 * Inserts an item into a tree window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6152 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6153 * handle: Handle to the tree to be inserted.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6154 * title: The text title of the entry.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6155 * icon: Handle to coresponding icon.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6156 * parent: Parent handle or 0 if root.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6157 * itemdata: Item specific data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6158 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6159 HTREEITEM API dw_tree_insert(HWND handle, char *title, HICN icon, HTREEITEM parent, void *itemdata)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6160 {
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6161 return dw_tree_insert_after(handle, NULL, title, icon, parent, itemdata);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6162 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6163
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6164 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6165 * Gets the text an item in a tree window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6166 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6167 * handle: Handle to the tree containing the item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6168 * item: Handle of the item to be modified.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6169 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6170 char * API dw_tree_get_title(HWND handle, HTREEITEM item)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6171 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6172 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6173 DW_MUTEX_LOCK;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6174 NSMutableArray *array = (NSMutableArray *)item;
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6175 NSString *nstr = (NSString *)[array objectAtIndex:1];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6176 DW_MUTEX_UNLOCK;
680
db315779a283 Initial tree support, lots more to do but basics are there.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 679
diff changeset
6177 return strdup([nstr UTF8String]);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6178 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6179
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6180 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6181 * Gets the text an item in a tree window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6182 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6183 * handle: Handle to the tree containing the item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6184 * item: Handle of the item to be modified.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6185 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6186 HTREEITEM API dw_tree_get_parent(HWND handle, HTREEITEM item)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6187 {
881
7b2750744552 Implemented dw_tree_get_parent() for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 873
diff changeset
6188 int _locked_by_me = FALSE;
7b2750744552 Implemented dw_tree_get_parent() for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 873
diff changeset
6189 HTREEITEM parent;
1064
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
6190 DWTree *tree = handle;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6191
881
7b2750744552 Implemented dw_tree_get_parent() for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 873
diff changeset
6192 DW_MUTEX_LOCK;
1064
b673b25bbd77 Fixed dw_tree_insert_after() so it works on Mac it previously functioned identical to dw_tree_insert().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1063
diff changeset
6193 parent = [tree parentForItem:item];
881
7b2750744552 Implemented dw_tree_get_parent() for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 873
diff changeset
6194 DW_MUTEX_UNLOCK;
7b2750744552 Implemented dw_tree_get_parent() for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 873
diff changeset
6195 return parent;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6196 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6197
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6198 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6199 * Sets the text and icon of an item in a tree window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6200 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6201 * handle: Handle to the tree containing the item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6202 * item: Handle of the item to be modified.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6203 * title: The text title of the entry.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6204 * icon: Handle to coresponding icon.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6205 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6206 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, HICN icon)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6207 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6208 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6209 DW_MUTEX_LOCK;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6210 DWTree *tree = handle;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6211 NSMutableArray *array = (NSMutableArray *)item;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
6212 DW_LOCAL_POOL_IN;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6213
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6214 if(title)
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6215 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6216 NSString *oldstr = [array objectAtIndex:1];
935
114729f5aedc Needed to retain NSStrings in the tree view on Mac to prevent crashes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 934
diff changeset
6217 NSString *nstr = [[NSString stringWithUTF8String:title] retain];
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6218 [array replaceObjectAtIndex:1 withObject:nstr];
935
114729f5aedc Needed to retain NSStrings in the tree view on Mac to prevent crashes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 934
diff changeset
6219 [oldstr release];
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6220 }
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6221 if(icon)
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6222 {
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6223 [array replaceObjectAtIndex:0 withObject:icon];
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6224 }
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6225 [tree reloadData];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
6226 DW_LOCAL_POOL_OUT;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6227 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6228 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6229
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6230 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6231 * Sets the item data of a tree item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6232 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6233 * handle: Handle to the tree containing the item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6234 * item: Handle of the item to be modified.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6235 * itemdata: User defined data to be associated with item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6236 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6237 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6238 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6239 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6240 DW_MUTEX_LOCK;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6241 NSMutableArray *array = (NSMutableArray *)item;
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6242 [array replaceObjectAtIndex:2 withObject:[NSValue valueWithPointer:itemdata]];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6243 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6244 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6245
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6246 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6247 * Gets the item data of a tree item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6248 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6249 * handle: Handle to the tree containing the item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6250 * item: Handle of the item to be modified.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6251 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6252 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6253 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6254 int _locked_by_me = FALSE;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6255 void *result = NULL;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6256 DW_MUTEX_LOCK;
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6257 NSMutableArray *array = (NSMutableArray *)item;
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6258 NSValue *value = [array objectAtIndex:2];
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
6259 if(value)
1065
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6260 {
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6261 result = [value pointerValue];
25e0317335fc Switched from using NSPointerArray to NSMutableArray on Mac to avoid the duplicate string crashes
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1064
diff changeset
6262 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6263 DW_MUTEX_UNLOCK;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6264 return result;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6265 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6266
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6267 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6268 * Sets this item as the active selection.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6269 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6270 * handle: Handle to the tree window (widget) to be selected.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6271 * item: Handle to the item to be selected.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6272 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6273 void API dw_tree_item_select(HWND handle, HTREEITEM item)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6274 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6275 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6276 DW_MUTEX_LOCK;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6277 DWTree *tree = handle;
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6278 NSInteger itemIndex = [tree rowForItem:item];
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6279 if(itemIndex > -1)
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6280 {
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6281 [tree selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6282 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6283 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6284 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6285
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6286 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6287 * Removes all nodes from a tree.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6288 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6289 * handle: Handle to the window (widget) to be cleared.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6290 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6291 void API dw_tree_clear(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6292 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6293 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6294 DW_MUTEX_LOCK;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6295 DWTree *tree = handle;
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6296 [tree clear];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6297 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6298 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6299
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6300 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6301 * Expands a node on a tree.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6302 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6303 * handle: Handle to the tree window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6304 * item: Handle to node to be expanded.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6305 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6306 void API dw_tree_item_expand(HWND handle, HTREEITEM item)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6307 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6308 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6309 DW_MUTEX_LOCK;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6310 DWTree *tree = handle;
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6311 [tree expandItem:item];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6312 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6313 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6314
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6315 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6316 * Collapses a node on a tree.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6317 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6318 * handle: Handle to the tree window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6319 * item: Handle to node to be collapsed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6320 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6321 void API dw_tree_item_collapse(HWND handle, HTREEITEM item)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6322 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6323 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6324 DW_MUTEX_LOCK;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6325 DWTree *tree = handle;
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6326 [tree collapseItem:item];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6327 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6328 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6329
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6330 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6331 * Removes a node from a tree.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6332 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6333 * handle: Handle to the window (widget) to be cleared.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6334 * item: Handle to node to be deleted.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6335 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6336 void API dw_tree_item_delete(HWND handle, HTREEITEM item)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6337 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6338 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6339 DW_MUTEX_LOCK;
682
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6340 DWTree *tree = handle;
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6341 [tree deleteNode:item];
de4aa126fb2f Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 681
diff changeset
6342 [tree reloadData];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6343 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6344 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6345
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6346 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6347 * Create a container object to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6348 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6349 * id: An ID to be used for getting the resource from the
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6350 * resource file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6351 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
6352 HWND API dw_container_new(ULONG cid, int multi)
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
6353 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6354 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6355 DW_MUTEX_LOCK;
708
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
6356 DWContainer *cont = _cont_new(cid, multi);
668
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
6357 NSScrollView *scrollview = [cont scrollview];
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
6358 [scrollview setHasHorizontalScroller:YES];
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
6359 NSTableHeaderView *header = [[[NSTableHeaderView alloc] init] autorelease];
708
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
6360 [cont setHeaderView:header];
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
6361 [cont setTarget:cont];
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
6362 [cont setDoubleAction:@selector(doubleClicked:)];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6363 DW_MUTEX_UNLOCK;
708
5fe2ca5ef88b Fixes for container event handling. Also made container/listbox cells non-editable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 707
diff changeset
6364 return cont;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6365 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6366
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6367 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6368 * Sets up the container columns.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6369 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6370 * handle: Handle to the container to be configured.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6371 * flags: An array of unsigned longs with column flags.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6372 * titles: An array of strings with column text titles.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6373 * count: The number of columns (this should match the arrays).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6374 * separator: The column number that contains the main separator.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6375 * (this item may only be used in OS/2)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6376 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6377 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6378 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6379 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6380 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6381 int z;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6382 DWContainer *cont = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
6383
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6384 [cont setup];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
6385
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6386 for(z=0;z<count;z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6387 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6388 NSTableColumn *column = [[NSTableColumn alloc] init];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6389 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]];
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6390 if(flags[z] & DW_CFA_BITMAPORICON)
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6391 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6392 NSImageCell *imagecell = [[NSImageCell alloc] init];
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6393 [column setDataCell:imagecell];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6394 [imagecell release];
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6395 }
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6396 else if(flags[z] & DW_CFA_STRINGANDICON)
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6397 {
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6398 DWImageAndTextCell *browsercell = [[DWImageAndTextCell alloc] init];
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6399 [column setDataCell:browsercell];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6400 [browsercell release];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6401 }
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6402 /* Defaults to left justified so just handle right and center */
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6403 if(flags[z] & DW_CFA_RIGHT)
855
0103a8751ab4 Removed an unnecessary method in the container (rowCount) and implemented container column alignment.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 854
diff changeset
6404 {
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6405 [(NSCell *)[column dataCell] setAlignment:NSRightTextAlignment];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6406 [(NSCell *)[column headerCell] setAlignment:NSRightTextAlignment];
855
0103a8751ab4 Removed an unnecessary method in the container (rowCount) and implemented container column alignment.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 854
diff changeset
6407 }
0103a8751ab4 Removed an unnecessary method in the container (rowCount) and implemented container column alignment.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 854
diff changeset
6408 else if(flags[z] & DW_CFA_CENTER)
0103a8751ab4 Removed an unnecessary method in the container (rowCount) and implemented container column alignment.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 854
diff changeset
6409 {
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6410 [(NSCell *)[column dataCell] setAlignment:NSCenterTextAlignment];
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6411 [(NSCell *)[column headerCell] setAlignment:NSCenterTextAlignment];
855
0103a8751ab4 Removed an unnecessary method in the container (rowCount) and implemented container column alignment.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 854
diff changeset
6412 }
795
f23cad02cfb3 Make listbox, container and tree cells uneditable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 794
diff changeset
6413 [column setEditable:NO];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6414 [cont addTableColumn:column];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6415 [cont addColumn:column andType:(int)flags[z]];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6416 [column release];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
6417 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6418 DW_MUTEX_UNLOCK;
986
87dc0f5f96d0 Fix return type of dw_listbox_selected() to be "int" instead of "unsigned int" to allow -1 return.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 983
diff changeset
6419 return DW_ERROR_NONE;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6420 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6421
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6422 /*
1744
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6423 * Configures the main filesystem columnn title for localization.
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6424 * Parameters:
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6425 * handle: Handle to the container to be configured.
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6426 * title: The title to be displayed in the main column.
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6427 */
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6428 void API dw_filesystem_set_column_title(HWND handle, char *title)
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6429 {
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6430 char *newtitle = strdup(title ? title : "");
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6431
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6432 dw_window_set_data(handle, "_dw_coltitle", newtitle);
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6433 }
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6434
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6435 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6436 * Sets up the filesystem columns, note: filesystem always has an icon/filename field.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6437 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6438 * handle: Handle to the container to be configured.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6439 * flags: An array of unsigned longs with column flags.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6440 * titles: An array of strings with column text titles.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6441 * count: The number of columns (this should match the arrays).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6442 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6443 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6444 {
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6445 char **newtitles = malloc(sizeof(char *) * (count + 1));
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6446 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 1));
1744
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6447 char *coltitle = (char *)dw_window_get_data(handle, "_dw_coltitle");
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
6448 DWContainer *cont = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
6449
1744
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6450 newtitles[0] = coltitle ? coltitle : "Filename";
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6451
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6452 newflags[0] = DW_CFA_STRINGANDICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR;
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6453
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6454 memcpy(&newtitles[1], titles, sizeof(char *) * count);
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6455 memcpy(&newflags[1], flags, sizeof(unsigned long) * count);
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6456
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6457 dw_container_setup(handle, newflags, newtitles, count + 1, 0);
813
7fa26d8cc8d0 Fix for column click handler not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 812
diff changeset
6458 [cont setFilesystem:YES];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
6459
1744
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6460 if(coltitle)
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6461 {
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6462 dw_window_set_data(handle, "_dw_coltitle", NULL);
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6463 free(coltitle);
535e8c19a13d Added dw_filesystem_set_column_title() function to aid in localization.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1740
diff changeset
6464 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6465 free(newtitles);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6466 free(newflags);
986
87dc0f5f96d0 Fix return type of dw_listbox_selected() to be "int" instead of "unsigned int" to allow -1 return.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 983
diff changeset
6467 return DW_ERROR_NONE;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6468 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6469
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6470 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6471 * Allocates memory used to populate a container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6472 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6473 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6474 * rowcount: The number of items to be populated.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6475 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6476 void * API dw_container_alloc(HWND handle, int rowcount)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6477 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6478 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6479 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6480 DWContainer *cont = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6481 [cont addRows:rowcount];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6482 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6483 return cont;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6484 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6485
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6486 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6487 * Sets an item in specified row and column to the given data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6488 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6489 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6490 * pointer: Pointer to the allocated memory in dw_container_alloc().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6491 * column: Zero based column of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6492 * row: Zero based row of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6493 * data: Pointer to the data to be added.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6494 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6495 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6496 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6497 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6498 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6499 DWContainer *cont = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6500 id object = nil;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6501 int type = [cont cellType:column];
801
5d8e4ecb7820 Think we need to ignore the last add point when the pointer argument is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 800
diff changeset
6502 int lastadd = 0;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6503
801
5d8e4ecb7820 Think we need to ignore the last add point when the pointer argument is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 800
diff changeset
6504 /* If pointer is NULL we are getting a change request instead of set */
5d8e4ecb7820 Think we need to ignore the last add point when the pointer argument is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 800
diff changeset
6505 if(pointer)
5d8e4ecb7820 Think we need to ignore the last add point when the pointer argument is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 800
diff changeset
6506 {
5d8e4ecb7820 Think we need to ignore the last add point when the pointer argument is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 800
diff changeset
6507 lastadd = [cont lastAddPoint];
5d8e4ecb7820 Think we need to ignore the last add point when the pointer argument is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 800
diff changeset
6508 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6509
1502
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6510 if(data)
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6511 {
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6512 if(type & DW_CFA_BITMAPORICON)
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6513 {
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6514 object = *((NSImage **)data);
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6515 }
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6516 else if(type & DW_CFA_STRING)
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6517 {
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6518 char *str = *((char **)data);
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6519 object = [ NSString stringWithUTF8String:str ];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6520 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6521 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6522 {
1502
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6523 char textbuffer[101] = {0};
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6524
1502
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6525 if(type & DW_CFA_ULONG)
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6526 {
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6527 ULONG tmp = *((ULONG *)data);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6528
1502
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6529 snprintf(textbuffer, 100, "%lu", tmp);
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6530 }
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6531 else if(type & DW_CFA_DATE)
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6532 {
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6533 struct tm curtm;
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6534 CDATE cdate = *((CDATE *)data);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6535
1502
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6536 memset( &curtm, 0, sizeof(curtm) );
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6537 curtm.tm_mday = cdate.day;
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6538 curtm.tm_mon = cdate.month - 1;
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6539 curtm.tm_year = cdate.year - 1900;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6540
1502
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6541 strftime(textbuffer, 100, "%x", &curtm);
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6542 }
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6543 else if(type & DW_CFA_TIME)
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6544 {
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6545 struct tm curtm;
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6546 CTIME ctime = *((CTIME *)data);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6547
1502
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6548 memset( &curtm, 0, sizeof(curtm) );
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6549 curtm.tm_hour = ctime.hours;
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6550 curtm.tm_min = ctime.minutes;
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6551 curtm.tm_sec = ctime.seconds;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6552
1502
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6553 strftime(textbuffer, 100, "%X", &curtm);
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6554 }
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6555 if(textbuffer[0])
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6556 object = [ NSString stringWithUTF8String:textbuffer ];
dc41efe8a53f Allow passing NULL to dw_container_change/set_item() APIs on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1498
diff changeset
6557 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6558 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
6559
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6560 [cont editCell:object at:(row+lastadd) and:column];
794
e9bc14c5c72d Test fix for containers (and probably listboxes) not showing their content changes immediately.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 793
diff changeset
6561 [cont setNeedsDisplay:YES];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6562 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6563 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6564
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6565 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6566 * Changes an existing item in specified row and column to the given data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6567 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6568 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6569 * column: Zero based column of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6570 * row: Zero based row of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6571 * data: Pointer to the data to be added.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6572 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6573 void API dw_container_change_item(HWND handle, int column, int row, void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6574 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6575 dw_container_set_item(handle, NULL, column, row, data);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6576 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6577
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6578 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6579 * Changes an existing item in specified row and column to the given data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6580 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6581 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6582 * column: Zero based column of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6583 * row: Zero based row of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6584 * data: Pointer to the data to be added.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6585 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6586 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6587 {
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6588 dw_container_change_item(handle, column+1, row, data);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6589 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6590
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6591 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6592 * Changes an item in specified row and column to the given data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6593 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6594 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6595 * pointer: Pointer to the allocated memory in dw_container_alloc().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6596 * column: Zero based column of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6597 * row: Zero based row of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6598 * data: Pointer to the data to be added.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6599 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6600 void API dw_filesystem_change_file(HWND handle, int row, char *filename, HICN icon)
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6601 {
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6602 dw_filesystem_set_file(handle, NULL, row, filename, icon);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6603 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6604
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6605 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6606 * Sets an item in specified row and column to the given data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6607 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6608 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6609 * pointer: Pointer to the allocated memory in dw_container_alloc().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6610 * column: Zero based column of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6611 * row: Zero based row of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6612 * data: Pointer to the data to be added.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6613 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6614 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, HICN icon)
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
6615 {
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6616 int _locked_by_me = FALSE;
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6617 DW_MUTEX_LOCK;
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6618 DWContainer *cont = handle;
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6619 DWImageAndTextCell *browsercell;
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6620 int lastadd = 0;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6621
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6622 /* If pointer is NULL we are getting a change request instead of set */
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6623 if(pointer)
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6624 {
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6625 lastadd = [cont lastAddPoint];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6626 }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6627
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
6628 browsercell = [[[DWImageAndTextCell alloc] init] autorelease];
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6629 [browsercell setImage:icon];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6630 [browsercell setStringValue:[ NSString stringWithUTF8String:filename ]];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6631 [cont editCell:browsercell at:(row+lastadd) and:0];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6632 [cont setNeedsDisplay:YES];
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6633 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6634 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6635
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6636 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6637 * Sets an item in specified row and column to the given data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6638 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6639 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6640 * pointer: Pointer to the allocated memory in dw_container_alloc().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6641 * column: Zero based column of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6642 * row: Zero based row of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6643 * data: Pointer to the data to be added.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6644 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6645 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6646 {
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6647 dw_container_set_item(handle, pointer, column+1, row, data);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6648 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6649
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6650 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6651 * Gets column type for a container column
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6652 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6653 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6654 * column: Zero based column.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6655 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6656 int API dw_container_get_column_type(HWND handle, int column)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6657 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6658 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6659 DW_MUTEX_LOCK;
721
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6660 DWContainer *cont = handle;
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6661 int rc;
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6662 int flag = [cont cellType:column];
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6663 if(flag & DW_CFA_BITMAPORICON)
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6664 rc = DW_CFA_BITMAPORICON;
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6665 else if(flag & DW_CFA_STRING)
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6666 rc = DW_CFA_STRING;
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6667 else if(flag & DW_CFA_ULONG)
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6668 rc = DW_CFA_ULONG;
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6669 else if(flag & DW_CFA_DATE)
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6670 rc = DW_CFA_DATE;
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6671 else if(flag & DW_CFA_TIME)
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6672 rc = DW_CFA_TIME;
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6673 else
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6674 rc = 0;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6675 DW_MUTEX_UNLOCK;
721
56053f1af9ee Fixes for dw_container/filessystem_get_column_type from Mark Hessling... adding him to the copyright section.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 720
diff changeset
6676 return rc;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6677 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6678
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6679 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6680 * Gets column type for a filesystem container column
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6681 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6682 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6683 * column: Zero based column.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6684 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6685 int API dw_filesystem_get_column_type(HWND handle, int column)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6686 {
882
1e7b7f870d88 Experimental change to use a single column for holding the filename and icon on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 881
diff changeset
6687 return dw_container_get_column_type(handle, column+1);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6688 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6689
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6690 /*
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6691 * Sets the alternating row colors for container window (widget) handle.
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6692 * Parameters:
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6693 * handle: The window (widget) handle.
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6694 * oddcolor: Odd row background color in DW_RGB format or a default color index.
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6695 * evencolor: Even row background color in DW_RGB format or a default color index.
1210
5a016a5a7412 Slight change in design behavior for dw_container_set_row_bg()...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1206
diff changeset
6696 * DW_RGB_TRANSPARENT will disable coloring rows.
5a016a5a7412 Slight change in design behavior for dw_container_set_row_bg()...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1206
diff changeset
6697 * DW_CLR_DEFAULT will use the system default alternating row colors.
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6698 */
1291
b99b0b2c2826 Renamed dw_container_set_row_bg() to dw_container_set_stripe().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1288
diff changeset
6699 void API dw_container_set_stripe(HWND handle, unsigned long oddcolor, unsigned long evencolor)
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6700 {
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6701 int _locked_by_me = FALSE;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6702 DW_MUTEX_LOCK;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6703 DWContainer *cont = handle;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
6704 [cont setRowBgOdd:(oddcolor == DW_CLR_DEFAULT ? DW_RGB(230,230,230) : oddcolor)
1212
5271d5cb27ac Implemented dw_container_set_row_bg() on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1210
diff changeset
6705 andEven:(evencolor == DW_CLR_DEFAULT ? DW_RGB_TRANSPARENT : evencolor)];
1206
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6706 DW_MUTEX_UNLOCK;
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6707 }
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6708
c7bb48cda53a Switched from using NSBrowserCell to a DWImageAndTextCell subclass on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1204
diff changeset
6709 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6710 * Sets the width of a column in the container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6711 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6712 * handle: Handle to window (widget) of container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6713 * column: Zero based column of width being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6714 * width: Width of column in pixels.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6715 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6716 void API dw_container_set_column_width(HWND handle, int column, int width)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6717 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6718 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6719 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6720 DWContainer *cont = handle;
831
168b9db65825 Minor fix for dw_container_column_set_width() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 829
diff changeset
6721 if([cont filesystem])
168b9db65825 Minor fix for dw_container_column_set_width() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 829
diff changeset
6722 {
168b9db65825 Minor fix for dw_container_column_set_width() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 829
diff changeset
6723 column++;
168b9db65825 Minor fix for dw_container_column_set_width() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 829
diff changeset
6724 }
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6725 NSTableColumn *col = [cont getColumn:column];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6726
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6727 [col setWidth:width];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6728 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6729 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6730
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6731 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6732 * Sets the title of a row in the container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6733 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6734 * pointer: Pointer to the allocated memory in dw_container_alloc().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6735 * row: Zero based row of data being set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6736 * title: String title of the item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6737 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6738 void API dw_container_set_row_title(void *pointer, int row, char *title)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6739 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6740 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6741 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6742 DWContainer *cont = pointer;
821
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6743 int lastadd = [cont lastAddPoint];
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6744 [cont setRow:(row+lastadd) title:title];
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6745 DW_MUTEX_UNLOCK;
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6746 }
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6747
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6748
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6749 /*
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6750 * Sets the title of a row in the container.
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6751 * Parameters:
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6752 * handle: Handle to window (widget) of container.
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6753 * row: Zero based row of data being set.
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6754 * title: String title of the item.
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6755 */
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6756 void API dw_container_change_row_title(HWND handle, int row, char *title)
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6757 {
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6758 int _locked_by_me = FALSE;
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6759 DW_MUTEX_LOCK;
00fa951abeb5 Fix for dw_container_set_row_title() misbehavior on Mac and implemented dw_container_change_row_title().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 813
diff changeset
6760 DWContainer *cont = handle;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6761 [cont setRow:row title:title];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6762 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6763 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6764
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6765 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6766 * Sets the title of a row in the container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6767 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6768 * handle: Handle to the container window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6769 * pointer: Pointer to the allocated memory in dw_container_alloc().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6770 * rowcount: The number of rows to be inserted.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6771 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6772 void API dw_container_insert(HWND handle, void *pointer, int rowcount)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6773 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6774 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6775 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6776 DWContainer *cont = handle;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6777 [cont reloadData];
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6778 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6779 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6780
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6781 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6782 * Removes all rows from a container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6783 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6784 * handle: Handle to the window (widget) to be cleared.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6785 * redraw: TRUE to cause the container to redraw immediately.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6786 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6787 void API dw_container_clear(HWND handle, int redraw)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6788 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6789 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6790 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6791 DWContainer *cont = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6792 [cont clear];
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
6793 if(redraw)
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
6794 {
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
6795 [cont reloadData];
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
6796 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6797 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6798 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6799
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6800 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6801 * Removes the first x rows from a container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6802 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6803 * handle: Handle to the window (widget) to be deleted from.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6804 * rowcount: The number of rows to be deleted.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6805 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6806 void API dw_container_delete(HWND handle, int rowcount)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6807 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6808 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6809 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6810 DWContainer *cont = handle;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6811 int x;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6812
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6813 for(x=0;x<rowcount;x++)
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6814 {
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6815 [cont removeRow:0];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6816 }
1705
3fa0448d3a7e Fixed a bug in dw_container_delete_row() on Mac and potentially a similar bug in dw_container_delete().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1704
diff changeset
6817 [cont reloadData];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6818 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6819 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6820
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6821 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6822 * Scrolls container up or down.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6823 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6824 * handle: Handle to the window (widget) to be scrolled.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6825 * direction: DW_SCROLL_UP, DW_SCROLL_DOWN, DW_SCROLL_TOP or
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6826 * DW_SCROLL_BOTTOM. (rows is ignored for last two)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6827 * rows: The number of rows to be scrolled.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6828 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6829 void API dw_container_scroll(HWND handle, int direction, long rows)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6830 {
837
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
6831 DWContainer *cont = handle;
89d4bad9c96e Initial attempt at implementing the scrollbox on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 831
diff changeset
6832 NSScrollView *sv = [cont scrollview];
852
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6833 NSScroller *scrollbar = [sv verticalScroller];
855
0103a8751ab4 Removed an unnecessary method in the container (rowCount) and implemented container column alignment.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 854
diff changeset
6834 int rowcount = (int)[cont numberOfRowsInTableView:cont];
852
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6835 float currpos = [scrollbar floatValue];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6836 float change;
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6837
853
c27ce204302b Add safety check to avoid potential divide by zero.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 852
diff changeset
6838 /* Safety check */
c27ce204302b Add safety check to avoid potential divide by zero.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 852
diff changeset
6839 if(rowcount < 1)
c27ce204302b Add safety check to avoid potential divide by zero.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 852
diff changeset
6840 {
c27ce204302b Add safety check to avoid potential divide by zero.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 852
diff changeset
6841 return;
c27ce204302b Add safety check to avoid potential divide by zero.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 852
diff changeset
6842 }
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6843
853
c27ce204302b Add safety check to avoid potential divide by zero.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 852
diff changeset
6844 change = (float)rows/(float)rowcount;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
6845
852
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6846 switch(direction)
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6847 {
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6848 case DW_SCROLL_TOP:
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6849 {
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6850 [scrollbar setFloatValue:0];
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6851 break;
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6852 }
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6853 case DW_SCROLL_BOTTOM:
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6854 {
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6855 [scrollbar setFloatValue:1];
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6856 break;
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6857 }
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6858 case DW_SCROLL_UP:
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6859 {
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6860 float newpos = currpos - change;
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6861 if(newpos < 0)
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6862 {
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6863 newpos = 0;
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6864 }
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6865 [scrollbar setFloatValue:newpos];
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6866 break;
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6867 }
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6868 case DW_SCROLL_DOWN:
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6869 {
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6870 float newpos = currpos + change;
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6871 if(newpos > 1)
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6872 {
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6873 newpos = 1;
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6874 }
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6875 [scrollbar setFloatValue:newpos];
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6876 break;
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6877 }
bb582f89007a Implemented dw_container_scroll() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 851
diff changeset
6878 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6879 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6880
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6881 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6882 * Starts a new query of a container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6883 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6884 * handle: Handle to the window (widget) to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6885 * flags: If this parameter is DW_CRA_SELECTED it will only
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6886 * return items that are currently selected. Otherwise
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6887 * it will return all records in the container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6888 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6889 char * API dw_container_query_start(HWND handle, unsigned long flags)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6890 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6891 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6892 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6893 DWContainer *cont = handle;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6894 NSIndexSet *selected = [cont selectedRowIndexes];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6895 NSUInteger result = [selected indexGreaterThanOrEqualToIndex:0];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6896 char *retval = NULL;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6897
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6898 if(result != NSNotFound)
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6899 {
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6900 retval = [cont getRowTitle:(int)result];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6901 [cont setLastQueryPoint:(int)result];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6902 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6903 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6904 return retval;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6905 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6906
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6907 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6908 * Continues an existing query of a container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6909 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6910 * handle: Handle to the window (widget) to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6911 * flags: If this parameter is DW_CRA_SELECTED it will only
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6912 * return items that are currently selected. Otherwise
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6913 * it will return all records in the container.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6914 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6915 char * API dw_container_query_next(HWND handle, unsigned long flags)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6916 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6917 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6918 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6919 DWContainer *cont = handle;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6920 int lastQueryPoint = [cont lastQueryPoint];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6921 NSIndexSet *selected = [cont selectedRowIndexes];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6922 NSUInteger result = [selected indexGreaterThanIndex:lastQueryPoint];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6923 char *retval = NULL;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6924
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6925 if(result != NSNotFound)
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6926 {
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6927 retval = [cont getRowTitle:(int)result];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6928 [cont setLastQueryPoint:(int)result];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6929 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6930 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
6931 return retval;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6932 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6933
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6934 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6935 * Cursors the item with the text speficied, and scrolls to that item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6936 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6937 * handle: Handle to the window (widget) to be queried.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6938 * text: Text usually returned by dw_container_query().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6939 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6940 void API dw_container_cursor(HWND handle, char *text)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6941 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6942 int _locked_by_me = FALSE;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
6943 DW_LOCAL_POOL_IN;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6944 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6945 DWContainer *cont = handle;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6946 char *thistext;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6947 int x, count = (int)[cont numberOfRowsInTableView:cont];
1322
3f1ac800bf65 Initial fix for being able to do container string comparisons instead of pointer on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1318
diff changeset
6948 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp"));
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6949
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6950 for(x=0;x<count;x++)
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6951 {
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6952 thistext = [cont getRowTitle:x];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6953
1322
3f1ac800bf65 Initial fix for being able to do container string comparisons instead of pointer on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1318
diff changeset
6954 if((textcomp && thistext && strcmp(thistext, text) == 0) || (!textcomp && thistext == text))
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6955 {
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6956 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6957
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6958 [cont selectRowIndexes:selected byExtendingSelection:YES];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6959 [selected release];
1334
5e2ec37d1680 Attempt to make dw_container_cursor() scroll to the item on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1322
diff changeset
6960 [cont scrollRowToVisible:x];
1335
44f8a846f3c1 A couple minor code cleanups on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1334
diff changeset
6961 DW_MUTEX_UNLOCK;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
6962 DW_LOCAL_POOL_OUT;
1335
44f8a846f3c1 A couple minor code cleanups on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1334
diff changeset
6963 return;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6964 }
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6965 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6966 DW_MUTEX_UNLOCK;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
6967 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6968 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6969
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6970 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6971 * Deletes the item with the text speficied.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6972 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6973 * handle: Handle to the window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6974 * text: Text usually returned by dw_container_query().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6975 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6976 void API dw_container_delete_row(HWND handle, char *text)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6977 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6978 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6979 DW_MUTEX_LOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6980 DWContainer *cont = handle;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6981 char *thistext;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6982 int x, count = (int)[cont numberOfRowsInTableView:cont];
1322
3f1ac800bf65 Initial fix for being able to do container string comparisons instead of pointer on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1318
diff changeset
6983 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp"));
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6984
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6985 for(x=0;x<count;x++)
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6986 {
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6987 thistext = [cont getRowTitle:x];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
6988
1322
3f1ac800bf65 Initial fix for being able to do container string comparisons instead of pointer on all platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1318
diff changeset
6989 if((textcomp && thistext && strcmp(thistext, text) == 0) || (!textcomp && thistext == text))
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6990 {
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6991 [cont removeRow:x];
1705
3fa0448d3a7e Fixed a bug in dw_container_delete_row() on Mac and potentially a similar bug in dw_container_delete().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1704
diff changeset
6992 [cont reloadData];
1335
44f8a846f3c1 A couple minor code cleanups on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1334
diff changeset
6993 DW_MUTEX_UNLOCK;
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6994 return;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6995 }
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
6996 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
6997 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6998 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6999
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7000 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7001 * Optimizes the column widths so that all data is visible.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7002 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7003 * handle: Handle to the window (widget) to be optimized.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7004 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7005 void API dw_container_optimize(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7006 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7007 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7008 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7009 DWContainer *cont = handle;
856
9dc45928a75f Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 855
diff changeset
7010 [cont optimize];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7011 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7012 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7013
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7014 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7015 * Inserts an icon into the taskbar.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7016 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7017 * handle: Window handle that will handle taskbar icon messages.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7018 * icon: Icon handle to display in the taskbar.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7019 * bubbletext: Text to show when the mouse is above the icon.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7020 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7021 void API dw_taskbar_insert(HWND handle, HICN icon, char *bubbletext)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7022 {
1220
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7023 NSStatusItem *item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7024 NSImage *image = icon;
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7025 [item setImage:image];
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7026 if(bubbletext)
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7027 [item setToolTip:[NSString stringWithUTF8String:bubbletext]];
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7028 [item setTarget:handle];
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7029 [item setEnabled:YES];
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7030 [item setHighlightMode:YES];
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7031 [item sendActionOn:(NSLeftMouseUpMask|NSLeftMouseDownMask|NSRightMouseUpMask|NSRightMouseDownMask)];
1222
aac69b11e821 Fix to get button press events working from the task/statusbar on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1220
diff changeset
7032 [item setAction:@selector(mouseDown:)];
1220
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7033 dw_window_set_data(handle, "_dw_taskbar", item);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7034 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7035
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7036 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7037 * Deletes an icon from the taskbar.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7038 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7039 * handle: Window handle that was used with dw_taskbar_insert().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7040 * icon: Icon handle that was used with dw_taskbar_insert().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7041 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7042 void API dw_taskbar_delete(HWND handle, HICN icon)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7043 {
1220
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7044 NSStatusItem *item = dw_window_get_data(handle, "_dw_taskbar");
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7045 DW_LOCAL_POOL_IN;
1220
67ff39b9577c Initial implementation of dw_taskbar_* for the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1215
diff changeset
7046 [item release];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7047 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7048 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7049
1708
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7050 /* Internal function to keep HICNs from getting too big */
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7051 void _icon_resize(NSImage *image)
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7052 {
1709
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7053 if(image)
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7054 {
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7055 NSSize size = [image size];
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7056 if(size.width > 24 || size.height > 24)
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7057 {
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7058 if(size.width > 24)
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7059 size.width = 24;
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7060 if(size.height > 24)
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7061 size.height = 24;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
7062 [image setSize:size];
1709
de49c1f284b2 Safety check for the icon resize code on Mac and GTK.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1708
diff changeset
7063 }
1708
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7064 }
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7065 }
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7066
1713
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7067 /* Internal version that does not resize the image */
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7068 HICN _dw_icon_load(unsigned long resid)
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7069 {
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7070 NSBundle *bundle = [NSBundle mainBundle];
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7071 NSString *respath = [bundle resourcePath];
1770
2396655d43f1 Fix some warnings with Mac 10.8 and Xcode 4.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1769
diff changeset
7072 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid];
1713
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7073 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath];
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7074 return image;
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7075 }
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7076
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7077 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7078 * Obtains an icon from a module (or header in GTK).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7079 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7080 * module: Handle to module (DLL) in OS/2 and Windows.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7081 * id: A unsigned long id int the resources on OS/2 and
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7082 * Windows, on GTK this is converted to a pointer
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7083 * to an embedded XPM.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7084 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7085 HICN API dw_icon_load(unsigned long module, unsigned long resid)
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7086 {
1713
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
7087 NSImage *image = _dw_icon_load(resid);
1708
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7088 _icon_resize(image);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7089 return image;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7090 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7091
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7092 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7093 * Obtains an icon from a file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7094 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7095 * filename: Name of the file, omit extention to have
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7096 * DW pick the appropriate file extension.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7097 * (ICO on OS/2 or Windows, XPM on Unix)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7098 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7099 HICN API dw_icon_load_from_file(char *filename)
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7100 {
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7101 char *ext = _dw_get_image_extension( filename );
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7102
674
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
7103 NSString *nstr = [ NSString stringWithUTF8String:filename ];
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
7104 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7105 if(!image && ext)
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7106 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7107 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
674
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
7108 image = [[NSImage alloc] initWithContentsOfFile:nstr];
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
7109 }
1708
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7110 _icon_resize(image);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7111 return image;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7112 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7113
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7114 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7115 * Obtains an icon from data
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7116 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7117 * filename: Name of the file, omit extention to have
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7118 * DW pick the appropriate file extension.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7119 * (ICO on OS/2 or Windows, XPM on Unix)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7120 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7121 HICN API dw_icon_load_from_data(char *data, int len)
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7122 {
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7123 NSData *thisdata = [NSData dataWithBytes:data length:len];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7124 NSImage *image = [[NSImage alloc] initWithData:thisdata];
1708
cc10082567ed Similar code for Mac to keep HICNs from getting too big.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1705
diff changeset
7125 _icon_resize(image);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7126 return image;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7127 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7128
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7129 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7130 * Frees a loaded resource in OS/2 and Windows.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7131 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7132 * handle: Handle to icon returned by dw_icon_load().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7133 */
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7134 void API dw_icon_free(HICN handle)
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7135 {
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7136 NSImage *image = handle;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7137 DW_LOCAL_POOL_IN;
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
7138 [image release];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7139 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7140 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7141
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7142 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7143 * Create a new MDI Frame to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7144 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7145 * id: An ID to be used with dw_window_from_id or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7146 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7147 HWND API dw_mdi_new(unsigned long cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7148 {
684
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
7149 /* There isn't anything like quite like MDI on MacOS...
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
7150 * However we will make floating windows that hide
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
7151 * when the application is deactivated to simulate
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7152 * similar behavior.
684
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
7153 */
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
7154 DWMDI *mdi = [[DWMDI alloc] init];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7155 /* [mdi setTag:cid]; Why doesn't this work? */
684
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
7156 return mdi;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7157 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7158
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7159 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7160 * Creates a splitbar window (widget) with given parameters.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7161 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7162 * type: Value can be DW_VERT or DW_HORZ.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7163 * topleft: Handle to the window to be top or left.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7164 * bottomright: Handle to the window to be bottom or right.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7165 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7166 * A handle to a splitbar window or NULL on failure.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7167 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7168 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7169 {
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
7170 id tmpbox = dw_box_new(DW_VERT, 0);
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7171 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7172 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7173 DWSplitBar *split = [[DWSplitBar alloc] init];
668
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
7174 [split setDelegate:split];
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
7175 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7176 [split addSubview:tmpbox];
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
7177 [tmpbox autorelease];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7178 tmpbox = dw_box_new(DW_VERT, 0);
668
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
7179 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7180 [split addSubview:tmpbox];
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
7181 [tmpbox autorelease];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7182 if(type == DW_VERT)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7183 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7184 [split setVertical:NO];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7185 }
668
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
7186 else
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
7187 {
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
7188 [split setVertical:YES];
7b99731c6484 Fixes for splitbars (horizontal and vertical definitions are reversed).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 667
diff changeset
7189 }
753
590eebc9b61f Preset the splitbar percent to 50% since Leopard doesn't set it automatically.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 752
diff changeset
7190 /* Set the default percent to 50% split */
590eebc9b61f Preset the splitbar percent to 50% since Leopard doesn't set it automatically.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 752
diff changeset
7191 [split setPercent:50.0];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7192 /* [split setTag:cid]; Why doesn't this work? */
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7193 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7194 return split;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7195 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7196
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7197 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7198 * Sets the position of a splitbar (pecentage).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7199 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7200 * handle: The handle to the splitbar returned by dw_splitbar_new().
1117
9ca5de2e59f8 Fixed the dw_splitbar_set() comment documentation. The percent parameter was missing.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1115
diff changeset
7201 * percent: The position of the splitbar.
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7202 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7203 void API dw_splitbar_set(HWND handle, float percent)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7204 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7205 DWSplitBar *split = handle;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7206 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7207 DW_MUTEX_LOCK;
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7208 NSRect rect = [split frame];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7209 float pos;
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7210 /* Calculate the position based on the size */
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7211 if([split isVertical])
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7212 {
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7213 pos = rect.size.width * (percent / 100.0);
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7214 }
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7215 else
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7216 {
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7217 pos = rect.size.height * (percent / 100.0);
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7218 }
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7219 if(pos > 0)
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7220 {
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7221 [split setPosition:pos ofDividerAtIndex:0];
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7222 }
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7223 else
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7224 {
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7225 /* If we have no size.. wait until the resize
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7226 * event when we get an actual size to try
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7227 * to set the splitbar again.
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7228 */
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7229 [split setPercent:percent];
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7230 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7231 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7232 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7233
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7234 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7235 * Gets the position of a splitbar (pecentage).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7236 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7237 * handle: The handle to the splitbar returned by dw_splitbar_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7238 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7239 float API dw_splitbar_get(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7240 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7241 DWSplitBar *split = handle;
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7242 NSRect rect1 = [split frame];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7243 NSArray *subviews = [split subviews];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7244 NSView *view = [subviews objectAtIndex:0];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7245 NSRect rect2 = [view frame];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7246 float pos, total, retval = 0.0;
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7247 if([split isVertical])
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7248 {
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7249 total = rect1.size.width;
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7250 pos = rect2.size.width;
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7251 }
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7252 else
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7253 {
677
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7254 total = rect1.size.height;
99002595f549 Fixes for dw_splitbar_set() not working on an unsized window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 676
diff changeset
7255 pos = rect2.size.height;
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7256 }
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7257 if(total > 0)
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7258 {
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7259 retval = pos / total;
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
7260 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7261 return retval;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7262 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7263
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7264 /* Internal function to convert fontname to NSFont */
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7265 NSFont *_dw_font_by_name(char *fontname)
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7266 {
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7267 char *fontcopy = strdup(fontname);
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7268 char *name = strchr(fontcopy, '.');
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7269 NSFont *font = nil;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
7270
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7271 if(name)
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7272 {
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7273 int size = atoi(fontcopy);
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7274 *name = 0;
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7275 name++;
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7276 font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size];
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7277 }
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7278 free(fontcopy);
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7279 return font;
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7280 }
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7281
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7282 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7283 * Create a bitmap object to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7284 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7285 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7286 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7287 HWND API dw_bitmap_new(ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7288 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7289 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7290 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7291 NSImageView *bitmap = [[NSImageView alloc] init];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7292 [bitmap setImageFrameStyle:NSImageFrameNone];
1074
53fc692279fc Bitmap widgets shouldn't scale down images when the widget is smaller than the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1071
diff changeset
7293 [bitmap setImageScaling:NSScaleNone];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7294 [bitmap setEditable:NO];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7295 [bitmap setTag:cid];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7296 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7297 return bitmap;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7298 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7299
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7300 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7301 * Creates a pixmap with given parameters.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7302 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7303 * handle: Window handle the pixmap is associated with.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7304 * width: Width of the pixmap in pixels.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7305 * height: Height of the pixmap in pixels.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7306 * depth: Color depth of the pixmap.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7307 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7308 * A handle to a pixmap or NULL on failure.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7309 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7310 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7311 {
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7312 HPIXMAP pixmap;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7313
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7314 if(!(pixmap = calloc(1,sizeof(struct _hpixmap))))
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7315 return NULL;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7316 pixmap->width = width;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7317 pixmap->height = height;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7318 pixmap->handle = handle;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7319 pixmap->image = [[NSBitmapImageRep alloc]
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7320 initWithBitmapDataPlanes:NULL
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7321 pixelsWide:width
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7322 pixelsHigh:height
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7323 bitsPerSample:8
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7324 samplesPerPixel:4
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7325 hasAlpha:YES
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7326 isPlanar:NO
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7327 colorSpaceName:NSDeviceRGBColorSpace
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7328 bytesPerRow:0
909
c092eab43ae3 Experimental change to pixmap rendering. Switch from using NSImage to NSBitmapImageRef to store the image.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 902
diff changeset
7329 bitsPerPixel:0];
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7330 return pixmap;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7331 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7332
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7333 /* Function takes an NSImage and copies it into a flipped NSBitmapImageRep */
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7334 void _flip_image(NSImage *tmpimage, NSBitmapImageRep *image, NSSize size)
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7335 {
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7336 [NSGraphicsContext saveGraphicsState];
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7337 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
981
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7338 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort]
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7339 flipped:YES]];
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
7340 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease];
1590
9eef6f82ee50 Comment cleanup in the Mac source.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1586
diff changeset
7341 /* Make a new transform */
981
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7342 NSAffineTransform *t = [NSAffineTransform transform];
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7343
1590
9eef6f82ee50 Comment cleanup in the Mac source.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1586
diff changeset
7344 /* By scaling Y negatively, we effectively flip the image */
981
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7345 [t scaleXBy:1.0 yBy:-1.0];
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7346
1590
9eef6f82ee50 Comment cleanup in the Mac source.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1586
diff changeset
7347 /* But we also have to translate it back by its height */
981
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7348 [t translateXBy:0.0 yBy:-size.height];
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7349
1590
9eef6f82ee50 Comment cleanup in the Mac source.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1586
diff changeset
7350 /* Apply the transform */
981
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7351 [t concat];
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7352 [tmpimage drawAtPoint:NSMakePoint(0, 0) fromRect:NSMakeRect(0, 0, size.width, size.height)
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7353 operation:NSCompositeSourceOver fraction:1.0];
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7354 [NSGraphicsContext restoreGraphicsState];
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7355 }
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7356
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7357 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7358 * Creates a pixmap from a file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7359 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7360 * handle: Window handle the pixmap is associated with.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7361 * filename: Name of the file, omit extention to have
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7362 * DW pick the appropriate file extension.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7363 * (BMP on OS/2 or Windows, XPM on Unix)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7364 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7365 * A handle to a pixmap or NULL on failure.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7366 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7367 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7368 {
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7369 HPIXMAP pixmap;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7370 DW_LOCAL_POOL_IN;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7371 char *ext = _dw_get_image_extension( filename );
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7372
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7373 if(!(pixmap = calloc(1,sizeof(struct _hpixmap))))
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7374 {
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7375 DW_LOCAL_POOL_OUT;
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7376 return NULL;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7377 }
674
78f9aa6d6d89 Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 673
diff changeset
7378 NSString *nstr = [ NSString stringWithUTF8String:filename ];
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
7379 NSImage *tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7380 if(!tmpimage && ext)
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7381 {
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
7382 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
7383 tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7384 }
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7385 if(!tmpimage)
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7386 {
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7387 DW_LOCAL_POOL_OUT;
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7388 return NULL;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7389 }
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7390 NSSize size = [tmpimage size];
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7391 NSBitmapImageRep *image = [[NSBitmapImageRep alloc]
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7392 initWithBitmapDataPlanes:NULL
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7393 pixelsWide:size.width
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7394 pixelsHigh:size.height
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7395 bitsPerSample:8
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7396 samplesPerPixel:4
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7397 hasAlpha:YES
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7398 isPlanar:NO
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7399 colorSpaceName:NSDeviceRGBColorSpace
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7400 bytesPerRow:0
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7401 bitsPerPixel:0];
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7402 _flip_image(tmpimage, image, size);
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7403 pixmap->width = size.width;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7404 pixmap->height = size.height;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7405 pixmap->image = image;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7406 pixmap->handle = handle;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7407 DW_LOCAL_POOL_OUT;
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7408 return pixmap;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7409 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7410
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7411 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7412 * Creates a pixmap from memory.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7413 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7414 * handle: Window handle the pixmap is associated with.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7415 * data: Source of the image data
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7416 * (BMP on OS/2 or Windows, XPM on Unix)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7417 * le: length of data
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7418 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7419 * A handle to a pixmap or NULL on failure.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7420 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7421 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7422 {
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7423 HPIXMAP pixmap;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7424 DW_LOCAL_POOL_IN;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7425
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7426 if(!(pixmap = calloc(1,sizeof(struct _hpixmap))))
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7427 {
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7428 DW_LOCAL_POOL_OUT;
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7429 return NULL;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7430 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7431 NSData *thisdata = [NSData dataWithBytes:data length:len];
1557
030e9bddc1c9 Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1556
diff changeset
7432 NSImage *tmpimage = [[[NSImage alloc] initWithData:thisdata] autorelease];
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7433 if(!tmpimage)
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7434 {
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7435 DW_LOCAL_POOL_OUT;
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7436 return NULL;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7437 }
957
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7438 NSSize size = [tmpimage size];
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7439 NSBitmapImageRep *image = [[NSBitmapImageRep alloc]
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7440 initWithBitmapDataPlanes:NULL
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7441 pixelsWide:size.width
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7442 pixelsHigh:size.height
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7443 bitsPerSample:8
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7444 samplesPerPixel:4
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7445 hasAlpha:YES
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7446 isPlanar:NO
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7447 colorSpaceName:NSDeviceRGBColorSpace
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7448 bytesPerRow:0
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7449 bitsPerPixel:0];
beed3e7f9d4b Fixes to flip pixmaps when loading from file or data on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 954
diff changeset
7450 _flip_image(tmpimage, image, size);
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7451 pixmap->width = size.width;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7452 pixmap->height = size.height;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7453 pixmap->image = image;
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7454 pixmap->handle = handle;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7455 DW_LOCAL_POOL_OUT;
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7456 return pixmap;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7457 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7458
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7459 /*
890
5a96cc2695b9 Removed dw_pixmap_set_transparent_color() from unimplemented on the Mac since it is handled automaticaly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 888
diff changeset
7460 * Sets the transparent color for a pixmap
5a96cc2695b9 Removed dw_pixmap_set_transparent_color() from unimplemented on the Mac since it is handled automaticaly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 888
diff changeset
7461 * Parameters:
5a96cc2695b9 Removed dw_pixmap_set_transparent_color() from unimplemented on the Mac since it is handled automaticaly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 888
diff changeset
7462 * pixmap: Handle to a pixmap returned by
5a96cc2695b9 Removed dw_pixmap_set_transparent_color() from unimplemented on the Mac since it is handled automaticaly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 888
diff changeset
7463 * dw_pixmap_new..
5a96cc2695b9 Removed dw_pixmap_set_transparent_color() from unimplemented on the Mac since it is handled automaticaly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 888
diff changeset
7464 * color: transparent color
5a96cc2695b9 Removed dw_pixmap_set_transparent_color() from unimplemented on the Mac since it is handled automaticaly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 888
diff changeset
7465 * Note: This does nothing on Mac as transparency
5a96cc2695b9 Removed dw_pixmap_set_transparent_color() from unimplemented on the Mac since it is handled automaticaly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 888
diff changeset
7466 * is handled automatically
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7467 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7468 void API dw_pixmap_set_transparent_color( HPIXMAP pixmap, ULONG color )
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7469 {
890
5a96cc2695b9 Removed dw_pixmap_set_transparent_color() from unimplemented on the Mac since it is handled automaticaly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 888
diff changeset
7470 /* Don't do anything */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7471 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7472
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7473 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7474 * Creates a pixmap from internal resource graphic specified by id.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7475 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7476 * handle: Window handle the pixmap is associated with.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7477 * id: Resource ID associated with requested pixmap.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7478 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7479 * A handle to a pixmap or NULL on failure.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7480 */
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
7481 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG resid)
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
7482 {
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7483 HPIXMAP pixmap;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7484 DW_LOCAL_POOL_IN;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7485
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7486 if(!(pixmap = calloc(1,sizeof(struct _hpixmap))))
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7487 {
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7488 DW_LOCAL_POOL_OUT;
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7489 return NULL;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7490 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7491
670
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
7492 NSBundle *bundle = [NSBundle mainBundle];
0b920d0dc13e Implemented bitmap buttons and pixmaps from bundle resources.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 669
diff changeset
7493 NSString *respath = [bundle resourcePath];
1770
2396655d43f1 Fix some warnings with Mac 10.8 and Xcode 4.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1769
diff changeset
7494 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid];
1318
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7495 NSImage *temp = [[NSImage alloc] initWithContentsOfFile:filepath];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
7496
1318
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7497 if(temp)
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7498 {
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7499 NSSize size = [temp size];
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7500 NSBitmapImageRep *image = [[NSBitmapImageRep alloc]
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7501 initWithBitmapDataPlanes:NULL
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7502 pixelsWide:size.width
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7503 pixelsHigh:size.height
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7504 bitsPerSample:8
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7505 samplesPerPixel:4
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7506 hasAlpha:YES
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7507 isPlanar:NO
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7508 colorSpaceName:NSDeviceRGBColorSpace
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7509 bytesPerRow:0
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7510 bitsPerPixel:0];
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7511 _flip_image(temp, image, size);
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7512 pixmap->width = size.width;
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7513 pixmap->height = size.height;
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7514 pixmap->image = image;
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7515 pixmap->handle = handle;
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7516 [temp release];
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7517 return pixmap;
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7518 }
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7519 free(pixmap);
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7520 DW_LOCAL_POOL_OUT;
1318
ebd67be26f43 Fixed some issues and deprecations building with Xcode 4.2 on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1314
diff changeset
7521 return NULL;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7522 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7523
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7524 /*
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7525 * Sets the font used by a specified pixmap.
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7526 * Normally the pixmap font is obtained from the associated window handle.
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7527 * However this can be used to override that, or for pixmaps with no window.
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7528 * Parameters:
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7529 * pixmap: Handle to a pixmap returned by dw_pixmap_new() or
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7530 * passed to the application via a callback.
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7531 * fontname: Name and size of the font in the form "size.fontname"
1147
091ed7c20b3f Implemented dw_pixmap_set_font() on Windows. Added to export files on Windows and OS/2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1146
diff changeset
7532 * Returns:
091ed7c20b3f Implemented dw_pixmap_set_font() on Windows. Added to export files on Windows and OS/2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1146
diff changeset
7533 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure.
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7534 */
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7535 int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname)
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7536 {
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7537 if(pixmap)
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7538 {
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7539 NSFont *font = _dw_font_by_name(fontname);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
7540
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7541 if(font)
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7542 {
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7543 DW_LOCAL_POOL_IN;
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7544 NSFont *oldfont = pixmap->font;
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7545 [font retain];
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7546 pixmap->font = font;
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7547 if(oldfont)
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7548 [oldfont release];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7549 DW_LOCAL_POOL_OUT;
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7550 return DW_ERROR_NONE;
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7551 }
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7552 }
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7553 return DW_ERROR_GENERAL;
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7554 }
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7555
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7556 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7557 * Destroys an allocated pixmap.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7558 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7559 * pixmap: Handle to a pixmap returned by
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7560 * dw_pixmap_new..
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7561 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7562 void API dw_pixmap_destroy(HPIXMAP pixmap)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7563 {
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7564 if(pixmap)
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7565 {
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7566 NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image;
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7567 NSFont *font = pixmap->font;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7568 DW_LOCAL_POOL_IN;
1146
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7569 [image release];
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7570 [font release];
9d97610b2140 Adding dw_pixmap_set_font() which is equivalent to dw_window_set_font() except for pixmaps.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1144
diff changeset
7571 free(pixmap);
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7572 DW_LOCAL_POOL_OUT;
981
536ec60ee433 Don't destroy a pixmap if the handle is null
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 980
diff changeset
7573 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7574 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7575
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7576 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7577 * Copies from one item to another.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7578 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7579 * dest: Destination window handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7580 * destp: Destination pixmap. (choose only one).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7581 * xdest: X coordinate of destination.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7582 * ydest: Y coordinate of destination.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7583 * width: Width of area to copy.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7584 * height: Height of area to copy.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7585 * src: Source window handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7586 * srcp: Source pixmap. (choose only one).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7587 * xsrc: X coordinate of source.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7588 * ysrc: Y coordinate of source.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7589 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7590 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7591 {
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7592 dw_pixmap_stretch_bitblt(dest, destp, xdest, ydest, width, height, src, srcp, xsrc, ysrc, -1, -1);
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7593 }
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7594
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7595 /*
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7596 * Copies from one surface to another allowing for stretching.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7597 * Parameters:
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7598 * dest: Destination window handle.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7599 * destp: Destination pixmap. (choose only one).
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7600 * xdest: X coordinate of destination.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7601 * ydest: Y coordinate of destination.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7602 * width: Width of the target area.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7603 * height: Height of the target area.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7604 * src: Source window handle.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7605 * srcp: Source pixmap. (choose only one).
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7606 * xsrc: X coordinate of source.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7607 * ysrc: Y coordinate of source.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7608 * srcwidth: Width of area to copy.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7609 * srcheight: Height of area to copy.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7610 * Returns:
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7611 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure.
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7612 */
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7613 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight)
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7614 {
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7615 DWBitBlt *bltinfo = calloc(1, sizeof(DWBitBlt));
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7616 NSValue* bi;
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7617 DW_LOCAL_POOL_IN;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
7618
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7619 bi = [NSValue valueWithPointer:bltinfo];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7620
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7621 /* Sanity checks */
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
7622 if((!dest && !destp) || (!src && !srcp) ||
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7623 ((srcwidth == -1 || srcheight == -1) && srcwidth != srcheight))
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7624 {
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7625 DW_LOCAL_POOL_OUT;
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7626 return DW_ERROR_GENERAL;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7627 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
7628
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7629 /* Fill in the information */
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7630 bltinfo->dest = dest;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7631 bltinfo->src = src;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7632 bltinfo->xdest = xdest;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7633 bltinfo->ydest = ydest;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7634 bltinfo->width = width;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7635 bltinfo->height = height;
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7636 bltinfo->xsrc = xsrc;
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7637 bltinfo->ysrc = ysrc;
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7638 bltinfo->srcwidth = srcwidth;
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7639 bltinfo->srcheight = srcheight;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7640
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7641 if(destp)
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7642 {
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7643 bltinfo->dest = (id)destp->image;
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7644 }
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7645 if(srcp)
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7646 {
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
7647 id object = bltinfo->src = (id)srcp->image;
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
7648 [object retain];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7649 }
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7650 if(DWThread == (DWTID)-1)
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7651 [DWObj doBitBlt:bi];
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7652 else
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7653 [DWObj performSelectorOnMainThread:@selector(doBitBlt:) withObject:bi waitUntilDone:YES];
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
7654 DW_LOCAL_POOL_OUT;
1247
93607596cf85 Implemented dw_pixmap_stretch_bitblt() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1241
diff changeset
7655 return DW_ERROR_NONE;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7656 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7657
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7658 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7659 * Create a new static text window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7660 * Not available under OS/2, eCS
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7661 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7662 * text: The text to be display by the static text widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7663 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7664 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7665 HWND API dw_calendar_new(ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7666 {
729
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7667 DWCalendar *calendar = [[DWCalendar alloc] init];
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7668 [calendar setDatePickerMode:NSSingleDateMode];
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7669 [calendar setDatePickerStyle:NSClockAndCalendarDatePickerStyle];
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7670 [calendar setDatePickerElements:NSYearMonthDayDatePickerElementFlag];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7671 [calendar setTag:cid];
1120
b2e060f43329 Initialize the calendar control to the current date during creation on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1117
diff changeset
7672 [calendar setDateValue:[NSDate date]];
729
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7673 return calendar;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7674 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7675
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7676 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7677 * Sets the current date of a calendar
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7678 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7679 * handle: The handle to the calendar returned by dw_calendar_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7680 * year...
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7681 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7682 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7683 {
729
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7684 DWCalendar *calendar = handle;
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7685 NSDate *date;
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
7686 char buffer[101];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7687 DW_LOCAL_POOL_IN;
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
7688
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
7689 snprintf(buffer, 100, "%04d-%02d-%02d 00:00:00 +0600", year, month, day);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7690
729
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7691 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]];
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7692 [calendar setDateValue:date];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7693 [date release];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7694 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7695 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7696
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7697 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7698 * Gets the position of a splitbar (pecentage).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7699 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7700 * handle: The handle to the splitbar returned by dw_splitbar_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7701 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7702 void dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7703 {
729
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7704 DWCalendar *calendar = handle;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7705 DW_LOCAL_POOL_IN;
729
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7706 NSDate *date = [calendar dateValue];
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7707 NSDateFormatter *df = [[NSDateFormatter alloc] init];
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7708 [df setDateStyle:NSDateFormatterShortStyle];
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7709 NSString *nstr = [df stringFromDate:date];
6712e4211522 Switched to graphical calendar control style... and fixed date querying code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 728
diff changeset
7710 sscanf([ nstr UTF8String ], "%d/%d/%d", month, day, year);
730
d3fb3613726a Calendar control should return years with 4 digits not 2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 729
diff changeset
7711 if(*year < 70)
d3fb3613726a Calendar control should return years with 4 digits not 2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 729
diff changeset
7712 {
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7713 *year += 2000;
730
d3fb3613726a Calendar control should return years with 4 digits not 2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 729
diff changeset
7714 }
d3fb3613726a Calendar control should return years with 4 digits not 2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 729
diff changeset
7715 else if(*year < 100)
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7716 {
730
d3fb3613726a Calendar control should return years with 4 digits not 2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 729
diff changeset
7717 *year += 1900;
d3fb3613726a Calendar control should return years with 4 digits not 2.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 729
diff changeset
7718 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7719 [df release];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7720 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7721 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7722
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7723 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7724 * Causes the embedded HTML widget to take action.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7725 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7726 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7727 * action: One of the DW_HTML_* constants.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7728 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7729 void API dw_html_action(HWND handle, int action)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7730 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7731 WebView *html = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7732 switch(action)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7733 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7734 case DW_HTML_GOBACK:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7735 [html goBack];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7736 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7737 case DW_HTML_GOFORWARD:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7738 [html goForward];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7739 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7740 case DW_HTML_GOHOME:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7741 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7742 case DW_HTML_SEARCH:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7743 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7744 case DW_HTML_RELOAD:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7745 [html reload:html];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7746 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7747 case DW_HTML_STOP:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7748 [html stopLoading:html];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7749 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7750 case DW_HTML_PRINT:
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7751 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7752 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7753 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7754
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7755 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7756 * Render raw HTML code in the embedded HTML widget..
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7757 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7758 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7759 * string: String buffer containt HTML code to
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7760 * be rendered.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7761 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7762 * 0 on success.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7763 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7764 int API dw_html_raw(HWND handle, char *string)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7765 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7766 WebView *html = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7767 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7768 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7769 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7770
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7771 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7772 * Render file or web page in the embedded HTML widget..
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7773 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7774 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7775 * url: Universal Resource Locator of the web or
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7776 * file object to be rendered.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7777 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7778 * 0 on success.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7779 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7780 int API dw_html_url(HWND handle, char *url)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7781 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7782 WebView *html = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7783 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7784 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7785 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7786
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7787 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7788 * Create a new HTML window (widget) to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7789 * Not available under OS/2, eCS
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7790 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7791 * text: The default text to be in the entryfield widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7792 * id: An ID to be used with dw_window_from_id() or 0L.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7793 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7794 HWND API dw_html_new(unsigned long cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7795 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7796 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7797 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7798 WebView *web = [[WebView alloc] init];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7799 /* [web setTag:cid]; Why doesn't this work? */
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
7800 DW_MUTEX_UNLOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7801 return web;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7802 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7803
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7804 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7805 * Returns the current X and Y coordinates of the mouse pointer.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7806 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7807 * x: Pointer to variable to store X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7808 * y: Pointer to variable to store Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7809 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7810 void API dw_pointer_query_pos(long *x, long *y)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7811 {
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7812 NSPoint mouseLoc;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7813 mouseLoc = [NSEvent mouseLocation];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7814 if(x)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7815 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7816 *x = mouseLoc.x;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7817 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7818 if(y)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7819 {
946
c64d3ca566f9 Attempt at inverting the window position and mouse pointer coordinates on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 945
diff changeset
7820 *y = [[NSScreen mainScreen] frame].size.height - mouseLoc.y;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7821 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7822 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7823
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7824 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7825 * Sets the X and Y coordinates of the mouse pointer.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7826 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7827 * x: X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7828 * y: Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7829 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7830 void API dw_pointer_set_pos(long x, long y)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7831 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7832 /* From what I have read this isn't possible, agaist human interface rules */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7833 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7834
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7835 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7836 * Create a menu object to be popped up.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7837 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7838 * id: An ID to be used for getting the resource from the
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7839 * resource file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7840 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7841 HMENUI API dw_menu_new(ULONG cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7842 {
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
7843 NSMenu *menu = [[NSMenu alloc] init];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7844 [menu setAutoenablesItems:NO];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
7845 /* [menu setTag:cid]; Why doesn't this work? */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7846 return menu;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7847 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7848
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7849 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7850 * Create a menubar on a window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7851 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7852 * location: Handle of a window frame to be attached to.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7853 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7854 HMENUI API dw_menubar_new(HWND location)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7855 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7856 NSWindow *window = location;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7857 NSMenu *windowmenu = _generate_main_menu();
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7858 [[window contentView] setMenu:windowmenu];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7859 return (HMENUI)windowmenu;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7860 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7861
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7862 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7863 * Destroys a menu created with dw_menubar_new or dw_menu_new.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7864 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7865 * menu: Handle of a menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7866 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7867 void API dw_menu_destroy(HMENUI *menu)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7868 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7869 NSMenu *thismenu = *menu;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7870 DW_LOCAL_POOL_IN;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7871 [thismenu release];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
7872 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7873 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7874
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7875 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7876 * Pops up a context menu at given x and y coordinates.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7877 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7878 * menu: The handle the the existing menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7879 * parent: Handle to the window initiating the popup.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7880 * x: X coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7881 * y: Y coordinate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7882 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7883 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7884 {
702
e9a3d1da3d3e dw_menu_popup() now uses the coordinates specified instead of the event coorindates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 701
diff changeset
7885 NSMenu *thismenu = (NSMenu *)*menu;
711
82250177f814 Fix for popup menus not being created when window handle passed is a toplevel window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 710
diff changeset
7886 id object = parent;
82250177f814 Fix for popup menus not being created when window handle passed is a toplevel window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 710
diff changeset
7887 NSView *view = [object isKindOfClass:[NSWindow class]] ? [object contentView] : parent;
702
e9a3d1da3d3e dw_menu_popup() now uses the coordinates specified instead of the event coorindates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 701
diff changeset
7888 NSWindow *window = [view window];
701
c91a1b345f2e Fix for button press and context menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 700
diff changeset
7889 NSEvent *event = [DWApp currentEvent];
1225
f5b79d8b0694 Fixed positioning popup menu when the controlling window is not visible on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1222
diff changeset
7890 if(!window)
f5b79d8b0694 Fixed positioning popup menu when the controlling window is not visible on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1222
diff changeset
7891 window = [event window];
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
7892 [thismenu autorelease];
946
c64d3ca566f9 Attempt at inverting the window position and mouse pointer coordinates on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 945
diff changeset
7893 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y);
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7894 NSEvent* fake = [NSEvent mouseEventWithType:NSRightMouseDown
946
c64d3ca566f9 Attempt at inverting the window position and mouse pointer coordinates on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 945
diff changeset
7895 location:[window convertScreenToBase:p]
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7896 modifierFlags:0
702
e9a3d1da3d3e dw_menu_popup() now uses the coordinates specified instead of the event coorindates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 701
diff changeset
7897 timestamp:[event timestamp]
e9a3d1da3d3e dw_menu_popup() now uses the coordinates specified instead of the event coorindates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 701
diff changeset
7898 windowNumber:[window windowNumber]
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7899 context:[NSGraphicsContext currentContext]
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7900 eventNumber:1
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7901 clickCount:1
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
7902 pressure:0.0];
702
e9a3d1da3d3e dw_menu_popup() now uses the coordinates specified instead of the event coorindates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 701
diff changeset
7903 [NSMenu popUpContextMenu:thismenu withEvent:fake forView:view];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7904 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7905
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7906 char _removetilde(char *dest, char *src)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7907 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7908 int z, cur=0;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7909 char accel = '\0';
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7910
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7911 for(z=0;z<strlen(src);z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7912 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7913 if(src[z] != '~')
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7914 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7915 dest[cur] = src[z];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7916 cur++;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7917 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7918 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7919 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7920 accel = src[z+1];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7921 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7922 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7923 dest[cur] = 0;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7924 return accel;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7925 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7926
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7927 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7928 * Adds a menuitem or submenu to an existing menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7929 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7930 * menu: The handle the the existing menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7931 * title: The title text on the menu item to be added.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7932 * id: An ID to be used for message passing.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7933 * flags: Extended attributes to set on the menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7934 * end: If TRUE memu is positioned at the end of the menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7935 * check: If TRUE menu is "check"able.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7936 * flags: Extended attributes to set on the menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7937 * submenu: Handle to an existing menu to be a submenu or NULL.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7938 */
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
7939 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7940 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7941 NSMenu *menu = menux;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7942 NSMenu *submenu = submenux;
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
7943 DWMenuItem *item = NULL;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7944 if(strlen(title) == 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7945 {
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
7946 [menu addItem:[DWMenuItem separatorItem]];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7947 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7948 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7949 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7950 char accel[2];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7951 char *newtitle = malloc(strlen(title)+1);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7952 NSString *nstr;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7953
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7954 accel[0] = _removetilde(newtitle, title);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7955 accel[1] = 0;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7956
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7957 nstr = [ NSString stringWithUTF8String:newtitle ];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7958 free(newtitle);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7959
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
7960 item = [[[DWMenuItem alloc] initWithTitle:nstr
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
7961 action:@selector(menuHandler:)
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
7962 keyEquivalent:[ NSString stringWithUTF8String:accel ]] autorelease];
1312
c5db6c70905c Added code to remove signal handlers when objects are destroyed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1306
diff changeset
7963 [menu addItem:item];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
7964
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7965 [item setTag:itemid];
1517
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
7966 if(check)
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
7967 {
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
7968 [item setCheck:YES];
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
7969 if(flags & DW_MIS_CHECKED)
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
7970 {
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
7971 [item setState:NSOnState];
6506f29dfefc Implement automatic checking and unchecking of menu items on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1513
diff changeset
7972 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7973 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7974 if(flags & DW_MIS_DISABLED)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7975 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7976 [item setEnabled:NO];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7977 }
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
7978
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7979 if(submenux)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7980 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7981 [submenu setTitle:nstr];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7982 [menu setSubmenu:submenu forItem:item];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7983 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7984 return item;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7985 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7986 return item;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7987 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7988
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7989 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7990 * Sets the state of a menu item check.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7991 * Deprecated; use dw_menu_item_set_state()
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7992 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7993 * menu: The handle the the existing menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7994 * id: Menuitem id.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7995 * check: TRUE for checked FALSE for not checked.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7996 */
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
7997 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check)
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
7998 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
7999 id menu = menux;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8000 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8001
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8002 if(menuitem != nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8003 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8004 if(check)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8005 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8006 [menuitem setState:NSOnState];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8007 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8008 else
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8009 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8010 [menuitem setState:NSOffState];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8011 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8012 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8013 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8014
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8015 /*
1375
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8016 * Deletes the menu item specified.
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8017 * Parameters:
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8018 * menu: The handle to the menu in which the item was appended.
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8019 * id: Menuitem id.
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8020 * Returns:
1375
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8021 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8022 */
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8023 int API dw_menu_delete_item(HMENUI menux, unsigned long itemid)
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8024 {
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8025 id menu = menux;
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8026 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8027
1375
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8028 if(menuitem != nil)
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8029 {
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8030 [menu removeItem:menuitem];
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8031 return DW_ERROR_NONE;
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8032 }
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8033 return DW_ERROR_UNKNOWN;
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8034 }
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8035
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8036 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8037 * Sets the state of a menu item.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8038 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8039 * menu: The handle to the existing menu.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8040 * id: Menuitem id.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8041 * flags: DW_MIS_ENABLED/DW_MIS_DISABLED
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8042 * DW_MIS_CHECKED/DW_MIS_UNCHECKED
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8043 */
654
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
8044 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state)
80e253df49fd Implementing the menubar and hopefully popup menus.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 653
diff changeset
8045 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8046 id menu = menux;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8047 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8048
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8049 if(menuitem != nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8050 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8051 if(state & DW_MIS_CHECKED)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8052 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8053 [menuitem setState:NSOnState];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8054 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8055 else if(state & DW_MIS_UNCHECKED)
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8056 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8057 [menuitem setState:NSOffState];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8058 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8059 if(state & DW_MIS_ENABLED)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8060 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8061 [menuitem setEnabled:YES];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8062 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8063 else if(state & DW_MIS_DISABLED)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8064 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8065 [menuitem setEnabled:NO];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8066 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8067 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8068 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8069
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
8070 /* Gets the notebook page from associated ID */
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
8071 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid)
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
8072 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8073 NSArray *pages = [notebook tabViewItems];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8074 for(DWNotebookPage *notepage in pages)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8075 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8076 if([notepage pageid] == pageid)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8077 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8078 return notepage;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8079 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8080 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8081 return nil;
652
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
8082 }
ef0f484c6c4b Added even more... including first signal handling and notebooks among other controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 651
diff changeset
8083
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8084 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8085 * Create a notebook object to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8086 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8087 * id: An ID to be used for getting the resource from the
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8088 * resource file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8089 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
8090 HWND API dw_notebook_new(ULONG cid, int top)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8091 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8092 DWNotebook *notebook = [[DWNotebook alloc] init];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8093 [notebook setDelegate:notebook];
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
8094 /* [notebook setTag:cid]; Why doesn't this work? */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8095 return notebook;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8096 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8097
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8098 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8099 * Adds a new page to specified notebook.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8100 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8101 * handle: Window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8102 * flags: Any additional page creation flags.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8103 * front: If TRUE page is added at the beginning.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8104 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8105 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8106 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8107 DWNotebook *notebook = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8108 NSInteger page = [notebook pageid];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8109 DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil];
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8110 [notepage setPageid:(int)page];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8111 if(front)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8112 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8113 [notebook insertTabViewItem:notepage atIndex:(NSInteger)0];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8114 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8115 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8116 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8117 [notebook addTabViewItem:notepage];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8118 }
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
8119 [notepage autorelease];
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8120 [notebook setPageid:(int)(page+1)];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8121 return (unsigned long)page;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8122 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8123
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8124 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8125 * Remove a page from a notebook.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8126 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8127 * handle: Handle to the notebook widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8128 * pageid: ID of the page to be destroyed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8129 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8130 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8131 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8132 DWNotebook *notebook = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8133 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid);
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
8134 DW_LOCAL_POOL_IN;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8135
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8136 if(notepage != nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8137 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8138 [notebook removeTabViewItem:notepage];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8139 }
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
8140 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8141 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8142
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8143 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8144 * Queries the currently visible page ID.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8145 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8146 * handle: Handle to the notebook widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8147 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8148 unsigned long API dw_notebook_page_get(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8149 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8150 DWNotebook *notebook = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8151 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8152 return [notepage pageid];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8153 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8154
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8155 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8156 * Sets the currently visibale page ID.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8157 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8158 * handle: Handle to the notebook widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8159 * pageid: ID of the page to be made visible.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8160 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8161 void API dw_notebook_page_set(HWND handle, unsigned int pageid)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8162 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8163 DWNotebook *notebook = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8164 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8165
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8166 if(notepage != nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8167 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8168 [notebook selectTabViewItem:notepage];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8169 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8170 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8171
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8172 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8173 * Sets the text on the specified notebook tab.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8174 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8175 * handle: Notebook handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8176 * pageid: Page ID of the tab to set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8177 * text: Pointer to the text to set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8178 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8179 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, char *text)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8180 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8181 DWNotebook *notebook = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8182 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8183
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8184 if(notepage != nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8185 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8186 [notepage setLabel:[ NSString stringWithUTF8String:text ]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8187 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8188 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8189
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8190 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8191 * Sets the text on the specified notebook tab status area.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8192 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8193 * handle: Notebook handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8194 * pageid: Page ID of the tab to set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8195 * text: Pointer to the text to set.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8196 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8197 void API dw_notebook_page_set_status_text(HWND handle, ULONG pageid, char *text)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8198 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8199 /* Note supported here... do nothing */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8200 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8201
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8202 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8203 * Packs the specified box into the notebook page.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8204 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8205 * handle: Handle to the notebook to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8206 * pageid: Page ID in the notebook which is being packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8207 * page: Box handle to be packed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8208 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8209 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8210 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8211 DWNotebook *notebook = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8212 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8213
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8214 if(notepage != nil)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8215 {
667
28727d9a835c Fix for a rather serious notebook layout bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 666
diff changeset
8216 HWND tmpbox = dw_box_new(DW_VERT, 0);
28727d9a835c Fix for a rather serious notebook layout bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 666
diff changeset
8217 DWBox *box = tmpbox;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8218
667
28727d9a835c Fix for a rather serious notebook layout bug.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 666
diff changeset
8219 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8220 [notepage setView:box];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8221 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8222 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8223
1610
48a61abcd5bb Make sure source will build with Mac frameworks older than 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1607
diff changeset
8224 #ifndef NSWindowCollectionBehaviorFullScreenPrimary
48a61abcd5bb Make sure source will build with Mac frameworks older than 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1607
diff changeset
8225 #define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7)
48a61abcd5bb Make sure source will build with Mac frameworks older than 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1607
diff changeset
8226 #endif
48a61abcd5bb Make sure source will build with Mac frameworks older than 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1607
diff changeset
8227
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8228 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8229 * Create a new Window Frame.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8230 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8231 * owner: The Owner's window handle or HWND_DESKTOP.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8232 * title: The Window title.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8233 * flStyle: Style flags, see the PM reference.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8234 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8235 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8236 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
8237 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
8238 DW_MUTEX_LOCK;
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8239 NSRect frame = NSMakeRect(1,1,1,1);
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
8240 DWWindow *window = [[DWWindow alloc]
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8241 initWithContentRect:frame
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8242 styleMask:(flStyle)
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8243 backing:NSBackingStoreBuffered
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8244 defer:false];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8245
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8246 [window setTitle:[ NSString stringWithUTF8String:title ]];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8247
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8248 DWView *view = [[DWView alloc] init];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8249
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8250 [window setContentView:view];
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8251 [window setDelegate:view];
766
82cde14ec084 Enable recalculating the key view loop (keyboard focus list) automatically.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 763
diff changeset
8252 [window setAutorecalculatesKeyViewLoop:YES];
944
cdb7a53e5515 Some motion notify changes... so it can handle events without the mouse button pressed on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 943
diff changeset
8253 [window setAcceptsMouseMovedEvents:YES];
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
8254 [view release];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8255
1607
d7fcea7bfcf9 Add full screen support for resizable windows on Mac 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1593
diff changeset
8256 /* Enable full screen mode on resizeable windows */
d7fcea7bfcf9 Add full screen support for resizable windows on Mac 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1593
diff changeset
8257 if(flStyle & DW_FCF_SIZEBORDER)
d7fcea7bfcf9 Add full screen support for resizable windows on Mac 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1593
diff changeset
8258 {
d7fcea7bfcf9 Add full screen support for resizable windows on Mac 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1593
diff changeset
8259 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
d7fcea7bfcf9 Add full screen support for resizable windows on Mac 10.7.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1593
diff changeset
8260 }
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8261
684
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8262 /* If it isn't a toplevel window... */
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8263 if(hwndOwner)
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8264 {
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8265 id object = hwndOwner;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8266
684
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8267 /* Check to see if the parent is an MDI window */
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8268 if([object isMemberOfClass:[DWMDI class]])
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8269 {
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8270 /* Set the window level to be floating */
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8271 [window setLevel:NSFloatingWindowLevel];
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8272 [window setHidesOnDeactivate:YES];
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8273 }
014b02436c1f Added MDI simulation code... the MDI "window" will just be a box for
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 683
diff changeset
8274 }
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8275 DW_MUTEX_UNLOCK;
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8276 return (HWND)window;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8277 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8278
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8279 /*
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8280 * Call a function from the window (widget)'s context.
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8281 * Parameters:
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8282 * handle: Window handle of the widget.
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8283 * function: Function pointer to be called.
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8284 * data: Pointer to the data to be passed to the function.
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8285 */
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8286 void API dw_window_function(HWND handle, void *function, void *data)
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8287 {
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8288 void **params = calloc(2, sizeof(void *));
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
8289 NSValue *v;
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
8290 DW_LOCAL_POOL_IN;
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
8291 v = [NSValue valueWithPointer:params];
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8292 params[0] = function;
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8293 params[1] = data;
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8294 [DWObj performSelectorOnMainThread:@selector(doWindowFunc:) withObject:v waitUntilDone:YES];
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8295 free(params);
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
8296 DW_LOCAL_POOL_OUT;
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8297 }
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8298
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8299
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
8300 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8301 * Changes the appearance of the mouse pointer.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8302 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8303 * handle: Handle to widget for which to change.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8304 * cursortype: ID of the pointer you want.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8305 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8306 void API dw_window_set_pointer(HWND handle, int pointertype)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8307 {
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8308 id object = handle;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8309
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8310 if([ object isKindOfClass:[ NSView class ] ])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8311 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8312 NSView *view = handle;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8313
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8314 if(pointertype == DW_POINTER_DEFAULT)
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8315 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8316 [view discardCursorRects];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8317 }
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8318 else if(pointertype == DW_POINTER_ARROW)
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8319 {
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8320 NSRect rect = [view frame];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8321 NSCursor *cursor = [NSCursor arrowCursor];
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8322
669
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8323 [view addCursorRect:rect cursor:cursor];
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8324 }
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8325 /* No cursor for DW_POINTER_CLOCK? */
62aae18e7b7d Implemented most of the listbox functions for the actual listbox control...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 668
diff changeset
8326 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8327 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8328
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8329 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8330 * Makes the window visible.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8331 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8332 * handle: The window handle to make visible.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8333 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8334 int API dw_window_show(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8335 {
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8336 NSObject *object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8337
1489
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8338 if([ object isMemberOfClass:[ DWWindow class ] ])
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8339 {
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8340 DWWindow *window = handle;
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8341 NSRect rect = [[window contentView] frame];
1795
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8342 id defaultitem = [window initialFirstResponder];
1489
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8343
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8344 if([window isMiniaturized])
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8345 {
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8346 [window deminiaturize:nil];
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8347 }
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8348 /* If we haven't been sized by a call.. */
1489
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8349 if(rect.size.width <= 1 || rect.size.height <= 1)
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8350 {
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8351 /* Determine the contents size */
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8352 dw_window_set_size(handle, 0, 0);
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8353 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8354 /* If the position was not set... generate a default
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8355 * default one in a similar pattern to SHELLPOSITION.
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8356 */
1489
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8357 if(![window shown])
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8358 {
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8359 static int defaultx = 0, defaulty = 0;
1497
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
8360 int cx = dw_screen_width(), cy = dw_screen_height();
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8361 int maxx = cx / 4, maxy = cy / 4;
1497
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
8362 NSPoint point;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8363
1489
4c1c44af201a Added auto-positioning and auto-sizing code for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1478
diff changeset
8364 rect = [window frame];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8365
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8366 defaultx += 20;
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8367 defaulty += 20;
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8368 if(defaultx > maxx)
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8369 defaultx = 20;
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8370 if(defaulty > maxy)
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8371 defaulty = 20;
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8372
1497
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
8373 point.x = defaultx;
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
8374 /* Take into account menu bar and inverted Y */
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
8375 point.y = cy - defaulty - (int)rect.size.height - 22;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8376
1497
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
8377 [window setFrameOrigin:point];
1490
5393b56ec6d0 Autoposition code should only be run the first time on Mac, regardless of whether it was needed or not.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1489
diff changeset
8378 [window setShown:YES];
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8379 }
930
b6ee515cad8a When getting dw_window_show() called on an unresized window... trigger a relayout on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 929
diff changeset
8380 [[window contentView] showWindow];
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8381 [window makeKeyAndOrderFront:nil];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8382
1782
d056a50196a9 Attempted fix at Mac textured background repeat problems. Thanks to Christoph Sinai
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1779
diff changeset
8383 if(!([window styleMask] & NSResizableWindowMask))
d056a50196a9 Attempted fix at Mac textured background repeat problems. Thanks to Christoph Sinai
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1779
diff changeset
8384 {
d056a50196a9 Attempted fix at Mac textured background repeat problems. Thanks to Christoph Sinai
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1779
diff changeset
8385 /* Fix incorrect repeat in displaying textured windows */
d056a50196a9 Attempted fix at Mac textured background repeat problems. Thanks to Christoph Sinai
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1779
diff changeset
8386 [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
d056a50196a9 Attempted fix at Mac textured background repeat problems. Thanks to Christoph Sinai
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1779
diff changeset
8387 [window setContentBorderThickness:0.0 forEdge:NSMinYEdge];
d056a50196a9 Attempted fix at Mac textured background repeat problems. Thanks to Christoph Sinai
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1779
diff changeset
8388 }
1795
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8389 if(defaultitem)
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8390 {
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8391 /* If there is a default item set, make it first responder */
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8392 [window makeFirstResponder:defaultitem];
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8393 }
735
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8394 }
b75be4860279 Possible fix for initial window creation with 0 size... not sure if the size I picked is good or not...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 734
diff changeset
8395 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8396 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8397
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8398 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8399 * Makes the window invisible.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8400 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8401 * handle: The window handle to make visible.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8402 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8403 int API dw_window_hide(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8404 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8405 NSObject *object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8406
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8407 if([ object isKindOfClass:[ NSWindow class ] ])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8408 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8409 NSWindow *window = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8410
733
8d5e5b89725f Fixed the crashing issue with dw_color_choose() it now functions properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 732
diff changeset
8411 [window orderOut:nil];
8d5e5b89725f Fixed the crashing issue with dw_color_choose() it now functions properly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 732
diff changeset
8412 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8413 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8414 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8415
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8416 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8417 * Sets the colors used by a specified window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8418 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8419 * handle: The window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8420 * fore: Foreground color in DW_RGB format or a default color index.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8421 * back: Background color in DW_RGB format or a default color index.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8422 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8423 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8424 {
739
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8425 id object = handle;
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8426 unsigned long _fore = _get_color(fore);
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8427 unsigned long _back = _get_color(back);
811
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8428 NSColor *fg = NULL;
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8429 NSColor *bg = NULL;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8430
811
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8431 /* Get the NSColor for non-default colors */
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8432 if(fore != DW_CLR_DEFAULT)
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8433 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8434 fg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_fore)/255.0 green: DW_GREEN_VALUE(_fore)/255.0 blue: DW_BLUE_VALUE(_fore)/255.0 alpha: 1];
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8435 }
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8436 if(back != DW_CLR_DEFAULT)
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8437 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8438 bg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_back)/255.0 green: DW_GREEN_VALUE(_back)/255.0 blue: DW_BLUE_VALUE(_back)/255.0 alpha: 1];
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8439 }
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8440
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8441 /* Get the textfield from the spinbutton */
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8442 if([object isMemberOfClass:[DWSpinButton class]])
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8443 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8444 object = [object textfield];
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8445 }
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8446 /* Get the cell on classes using NSCell */
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8447 if([object isKindOfClass:[NSTextField class]])
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8448 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8449 id cell = [object cell];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8450
811
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8451 if(fg)
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8452 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8453 [cell setTextColor:fg];
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8454 }
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8455 }
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8456 if([object isKindOfClass:[NSTextField class]] || [object isKindOfClass:[NSButton class]])
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8457 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8458 id cell = [object cell];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8459
811
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8460 if(bg)
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8461 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8462 [cell setBackgroundColor:bg];
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8463 }
739
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8464 }
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8465 else if([object isMemberOfClass:[DWBox class]])
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8466 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8467 DWBox *box = object;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8468
811
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8469 if(bg)
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8470 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8471 [box setColor:_back];
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8472 }
739
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8473 }
810
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
8474 else if([object isKindOfClass:[NSTableView class]])
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
8475 {
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
8476 DWContainer *cont = handle;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8477
811
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8478 if(bg)
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8479 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8480 [cont setBackgroundColor:bg];
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8481 }
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8482 if(fg)
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8483 {
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8484 [cont setForegroundColor:fg];
50ed3e92215b Changes for dw_window_set_color() so it works on pretty much any control we support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 810
diff changeset
8485 }
810
746cdd753e7a Added coloring support for the Container/Tree/Listbox controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 809
diff changeset
8486 }
1543
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
8487 else if([object isMemberOfClass:[DWMLE class]])
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
8488 {
b86a04751ea0 Refactor MLE code on Mac to be more like the Container and Tree code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1538
diff changeset
8489 DWMLE *mle = handle;
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
8490 if(bg)
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
8491 {
1130
c3138ffd0de0 Implemented foreground color changes for MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1129
diff changeset
8492 [mle setBackgroundColor:bg];
c3138ffd0de0 Implemented foreground color changes for MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1129
diff changeset
8493 }
c3138ffd0de0 Implemented foreground color changes for MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1129
diff changeset
8494 if(fg)
c3138ffd0de0 Implemented foreground color changes for MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1129
diff changeset
8495 {
c3138ffd0de0 Implemented foreground color changes for MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1129
diff changeset
8496 NSTextStorage *ts = [mle textStorage];
c3138ffd0de0 Implemented foreground color changes for MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1129
diff changeset
8497 [ts setForegroundColor:fg];
c3138ffd0de0 Implemented foreground color changes for MLE on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1129
diff changeset
8498 }
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
8499 }
739
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8500 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8501 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8502
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8503 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8504 * Sets the font used by a specified window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8505 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8506 * handle: The window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8507 * border: Size of the window border in pixels.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8508 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8509 int API dw_window_set_border(HWND handle, int border)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8510 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8511 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8512 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8513
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8514 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8515 * Sets the style of a given window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8516 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8517 * handle: Window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8518 * width: New width in pixels.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8519 * height: New height in pixels.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8520 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8521 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8522 {
1778
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
8523 id object = _text_handle(handle);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8524
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8525 if([object isMemberOfClass:[DWWindow class]])
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
8526 {
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
8527 DWWindow *window = object;
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8528 SEL sssm = NSSelectorFromString(@"setStyleMask");
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8529
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8530 if([window respondsToSelector:sssm])
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8531 {
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8532 IMP issm = [window methodForSelector:sssm];
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8533 int currentstyle = (int)[window styleMask];
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8534 int tmp;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8535
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8536 tmp = currentstyle | (int)mask;
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8537 tmp ^= mask;
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8538 tmp |= style;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8539
1773
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8540 issm(window, sssm, tmp);
da7786b8573f Check if classes respond to selectors on Mac for new, removed and deprecated methods to avoid compiler warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1772
diff changeset
8541 }
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
8542 }
740
bb3b2d804f0e Working on fonts some more.... setting a default label font that is smaller.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 739
diff changeset
8543 else if([object isKindOfClass:[NSTextField class]])
bb3b2d804f0e Working on fonts some more.... setting a default label font that is smaller.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 739
diff changeset
8544 {
bb3b2d804f0e Working on fonts some more.... setting a default label font that is smaller.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 739
diff changeset
8545 NSTextField *tf = object;
1778
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
8546 DWTextFieldCell *cell = [tf cell];
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
8547
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
8548 [cell setAlignment:(style & 0xF)];
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
8549 if(mask & DW_DT_VCENTER && [cell isMemberOfClass:[DWTextFieldCell class]])
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
8550 {
e71ab68198ce Minor cleanups for the Mac status text changes for 10.8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1776
diff changeset
8551 [cell setVCenter:(style & DW_DT_VCENTER ? YES : NO)];
859
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
8552 }
1788
9d499b162fe1 Discovered a breakage in OS/2 functionality when building
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1786
diff changeset
8553 if(mask & DW_DT_WORDBREAK && [cell isMemberOfClass:[DWTextFieldCell class]])
9d499b162fe1 Discovered a breakage in OS/2 functionality when building
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1786
diff changeset
8554 {
9d499b162fe1 Discovered a breakage in OS/2 functionality when building
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1786
diff changeset
8555 [cell setWraps:(style & DW_DT_WORDBREAK ? YES : NO)];
9d499b162fe1 Discovered a breakage in OS/2 functionality when building
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1786
diff changeset
8556 }
740
bb3b2d804f0e Working on fonts some more.... setting a default label font that is smaller.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 739
diff changeset
8557 }
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
8558 else if([object isMemberOfClass:[NSTextView class]])
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
8559 {
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
8560 NSTextView *tv = handle;
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
8561 [tv setAlignment:(style & mask)];
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
8562 }
763
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8563 else if([object isMemberOfClass:[DWButton class]])
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8564 {
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8565 DWButton *button = handle;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8566
763
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8567 if(mask & DW_BS_NOBORDER)
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8568 {
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8569 if(style & DW_BS_NOBORDER)
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8570 [button setBordered:NO];
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8571 else
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8572 [button setBordered:YES];
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8573 }
2cace4e6e69a Added DW_BS_NOBORDER style which can be set on buttons with dw_window_set_style() to make them flat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 762
diff changeset
8574 }
1314
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8575 else if([object isMemberOfClass:[DWMenuItem class]])
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8576 {
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8577 if(mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED))
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8578 {
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8579 if(style & DW_MIS_CHECKED)
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8580 [object setState:NSOnState];
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8581 else if(style & DW_MIS_UNCHECKED)
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8582 [object setState:NSOffState];
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8583 }
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8584 if(mask & (DW_MIS_ENABLED | DW_MIS_DISABLED))
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8585 {
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8586 if(style & DW_MIS_ENABLED)
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8587 [object setEnabled:YES];
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8588 else if(style & DW_MIS_DISABLED)
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8589 [object setEnabled:NO];
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8590 }
c969db49606e Initial commit allowing dw_window_set_style() to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1313
diff changeset
8591 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8592 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8593
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8594 /*
1795
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8595 * Sets the current focus item for a window/dialog.
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8596 * Parameters:
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8597 * handle: Handle to the dialog item to be focused.
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8598 * Remarks:
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8599 * This is for use after showing the window/dialog.
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8600 */
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8601 void API dw_window_set_focus(HWND handle)
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8602 {
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8603 id object = handle;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8604
1795
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8605 [[object window] makeFirstResponder:object];
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8606 }
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8607
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8608 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8609 * Sets the default focus item for a window/dialog.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8610 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8611 * window: Toplevel window or dialog.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8612 * defaultitem: Handle to the dialog item to be default.
1795
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8613 * Remarks:
9304241b7b33 Added new dw_window_set_focus() function and attempted to fix...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1792
diff changeset
8614 * This is for use before showing the window/dialog.
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8615 */
766
82cde14ec084 Enable recalculating the key view loop (keyboard focus list) automatically.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 763
diff changeset
8616 void API dw_window_default(HWND handle, HWND defaultitem)
82cde14ec084 Enable recalculating the key view loop (keyboard focus list) automatically.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 763
diff changeset
8617 {
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
8618 DWWindow *window = handle;
872
13debcad9757 Another test fix at reported crash in dw_window_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 867
diff changeset
8619 id object = defaultitem;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8620
872
13debcad9757 Another test fix at reported crash in dw_window_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 867
diff changeset
8621 if([window isKindOfClass:[NSWindow class]] && [object isKindOfClass:[NSControl class]])
864
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
8622 {
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
8623 [window setInitialFirstResponder:defaultitem];
ca01c7d95b80 Added some sanity checks for a couple of problem functions and default optimized container column width to 16 for image columns.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 860
diff changeset
8624 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8625 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8626
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8627 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8628 * Sets window to click the default dialog item when an ENTER is pressed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8629 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8630 * window: Window (widget) to look for the ENTER press.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8631 * next: Window (widget) to move to next (or click)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8632 */
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8633 void API dw_window_click_default(HWND handle, HWND next)
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8634 {
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8635 id object = handle;
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8636 id control = next;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8637
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
8638 if([object isMemberOfClass:[DWWindow class]])
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
8639 {
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
8640 if([control isMemberOfClass:[DWButton class]])
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
8641 {
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
8642 NSWindow *window = object;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8643
792
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
8644 [window setDefaultButtonCell:control];
fc6a626a96cc Initial groupbox support. Sizing of the content frame is not quite right yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 768
diff changeset
8645 }
768
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8646 }
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8647 else
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8648 {
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8649 if([control isMemberOfClass:[DWSpinButton class]])
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8650 {
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8651 control = [control textfield];
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8652 }
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8653 else if([control isMemberOfClass:[DWComboBox class]])
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8654 {
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8655 /* TODO: Figure out why the combobox can't be
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8656 * focused using makeFirstResponder method.
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8657 */
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8658 control = [control textfield];
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8659 }
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8660 [object setClickDefault:control];
7a236fdcf4ba Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 767
diff changeset
8661 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8662 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8663
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8664 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8665 * Captures the mouse input to this window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8666 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8667 * handle: Handle to receive mouse input.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8668 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8669 void API dw_window_capture(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8670 {
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
8671 /* Don't do anything for now */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8672 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8673
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8674 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8675 * Releases previous mouse capture.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8676 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8677 void API dw_window_release(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8678 {
949
451c71b7fdb1 Changed dw_window_capture() an dw_window_release() because the mouseDragged method does this already.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 948
diff changeset
8679 /* Don't do anything for now */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8680 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8681
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8682 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8683 * Changes a window's parent to newparent.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8684 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8685 * handle: The window handle to destroy.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8686 * newparent: The window's new parent window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8687 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8688 void API dw_window_reparent(HWND handle, HWND newparent)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8689 {
686
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8690 id object = handle;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8691
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
8692 if([object isMemberOfClass:[DWWindow class]])
686
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8693 {
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8694 /* We can't actually reparent on MacOS but if the
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8695 * new parent is an MDI window, change to be a
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8696 * floating window... otherwise set it to normal.
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8697 */
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8698 NSWindow *window = handle;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8699
686
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8700 /* If it isn't a toplevel window... */
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8701 if(newparent)
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8702 {
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8703 object = newparent;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8704
686
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8705 /* Check to see if the parent is an MDI window */
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8706 if([object isMemberOfClass:[DWMDI class]])
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8707 {
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8708 /* Set the window level to be floating */
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8709 [window setLevel:NSFloatingWindowLevel];
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8710 [window setHidesOnDeactivate:YES];
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8711 return;
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8712 }
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8713 }
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8714 /* Set the window back to a normal window */
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8715 [window setLevel:NSNormalWindowLevel];
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8716 [window setHidesOnDeactivate:NO];
218d676baf7f Implemented dw_window_reparent using the method used for MDI simulation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 685
diff changeset
8717 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8718 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8719
1051
6919854298fd Added dw_font_choose() on Windows for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1050
diff changeset
8720 /* Allows the user to choose a font using the system's font chooser dialog.
6919854298fd Added dw_font_choose() on Windows for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1050
diff changeset
8721 * Parameters:
6919854298fd Added dw_font_choose() on Windows for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1050
diff changeset
8722 * currfont: current font
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8723 * Returns:
1051
6919854298fd Added dw_font_choose() on Windows for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1050
diff changeset
8724 * A malloced buffer with the selected font or NULL on error.
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8725 */
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8726 char * API dw_font_choose(char *currfont)
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8727 {
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8728 /* Create the Color Chooser Dialog class. */
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8729 static DWFontChoose *fontDlg = nil;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8730 static NSFontManager *fontManager = nil;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8731 DWDialog *dialog;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8732 NSFont *font = nil;
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
8733
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8734 if(currfont)
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8735 font = _dw_font_by_name(currfont);
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
8736
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8737 if(fontDlg)
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8738 {
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8739 dialog = [fontDlg dialog];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8740 /* If someone is already waiting just return */
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8741 if(dialog)
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8742 {
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8743 return NULL;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8744 }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8745 }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8746 else
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8747 {
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8748 [NSFontManager setFontPanelFactory:[DWFontChoose class]];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8749 fontManager = [NSFontManager sharedFontManager];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8750 fontDlg = (DWFontChoose *)[fontManager fontPanel:YES];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8751 }
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
8752
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8753 dialog = dw_dialog_new(fontDlg);
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8754 if(font)
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8755 [fontManager setSelectedFont:font isMultiple:NO];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8756 else
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8757 [fontManager setSelectedFont:[NSFont fontWithName:@"Helvetica" size:9.0] isMultiple:NO];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8758 [fontDlg setDialog:dialog];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8759 [fontDlg setFontManager:fontManager];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8760 [fontManager orderFrontFontPanel:fontManager];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8761
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
8762
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8763 /* Wait for them to pick a color */
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8764 font = (NSFont *)dw_dialog_wait(dialog);
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8765 if(font)
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8766 {
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8767 NSString *fontname = [font displayName];
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8768 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]];
1068
efaa9ceeb253 Removed test for class member for itemdata in dw_tree_item_get_data()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1067
diff changeset
8769 return strdup([output UTF8String]);
1050
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8770 }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8771 return NULL;
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8772 }
48f43c975533 Added dw_font_choose() on the Mac for 2.1.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1048
diff changeset
8773
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8774 /* Internal function to return a pointer to an item struct
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8775 * with information about the packing information regarding object.
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8776 */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8777 Item *_box_item(id object)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8778 {
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8779 /* Find the item within the box it is packed into */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8780 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[DWGroupBox class]] || [object isKindOfClass:[NSControl class]])
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8781 {
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8782 DWBox *parent = (DWBox *)[object superview];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8783
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8784 /* Some controls are embedded in scrollviews...
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8785 * so get the parent of the scrollview in that case.
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8786 */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8787 if([object isKindOfClass:[NSTableView class]] && [parent isMemberOfClass:[NSClipView class]])
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8788 {
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8789 object = [parent superview];
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8790 parent = (DWBox *)[object superview];
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8791 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8792
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8793 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]])
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8794 {
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8795 Box *thisbox = [parent box];
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8796 Item *thisitem = thisbox->items;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8797 int z;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8798
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8799 for(z=0;z<thisbox->count;z++)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8800 {
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8801 if(thisitem[z].hwnd == object)
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8802 return &thisitem[z];
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8803 }
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8804 }
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8805 }
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8806 return NULL;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8807 }
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8808
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8809 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8810 * Sets the font used by a specified window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8811 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8812 * handle: The window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8813 * fontname: Name and size of the font in the form "size.fontname"
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8814 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8815 int API dw_window_set_font(HWND handle, char *fontname)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8816 {
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8817 NSFont *font = _dw_font_by_name(fontname);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8818
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8819 if(font)
740
bb3b2d804f0e Working on fonts some more.... setting a default label font that is smaller.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 739
diff changeset
8820 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
8821 id object = _text_handle(handle);
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8822 if([object window])
673
6d0f0dc7ff7c Some minor font fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 672
diff changeset
8823 {
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8824 [object lockFocus];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8825 [font set];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8826 [object unlockFocus];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8827 }
1040
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8828 if([object isMemberOfClass:[DWGroupBox class]])
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8829 {
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8830 [object setTitleFont:font];
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8831 }
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8832 else if([object isKindOfClass:[NSControl class]])
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8833 {
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8834 [object setFont:font];
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
8835 [[object cell] setFont:font];
673
6d0f0dc7ff7c Some minor font fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 672
diff changeset
8836 }
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
8837 else if([object isMemberOfClass:[DWRender class]])
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
8838 {
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
8839 DWRender *render = object;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
8840
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
8841 [render setFont:font];
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
8842 }
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8843 else
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8844 return DW_ERROR_UNKNOWN;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8845 /* If we changed the text... */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8846 Item *item = _box_item(handle);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8847
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8848 /* Check to see if any of the sizes need to be recalculated */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8849 if(item && (item->origwidth == -1 || item->origheight == -1))
1422
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
8850 {
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8851 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
1422
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
8852 /* Queue a redraw on the top-level window */
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
8853 _dw_redraw([object window], TRUE);
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
8854 }
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8855 return DW_ERROR_NONE;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8856 }
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
8857 return DW_ERROR_UNKNOWN;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8858 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8859
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8860 /*
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8861 * Returns the current font for the specified window
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8862 * Parameters:
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8863 * handle: The window handle from which to obtain the font.
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8864 */
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8865 char * API dw_window_get_font(HWND handle)
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8866 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
8867 id object = _text_handle(handle);
1040
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8868 NSFont *font = nil;
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8869
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8870 if([object isMemberOfClass:[DWGroupBox class]])
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8871 {
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8872 font = [object titleFont];
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8873 }
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8874 else if([object isKindOfClass:[NSControl class]] || [object isMemberOfClass:[DWRender class]])
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8875 {
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8876 font = [object font];
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8877 }
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8878 if(font)
7ea8a428e0cc Attempt at adding support for groupboxes to dw_window_set/get_font() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1027
diff changeset
8879 {
1041
6a57bf20d8f9 Return displayName property instead of fontName property in dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1040
diff changeset
8880 NSString *fontname = [font displayName];
739
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8881 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]];
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8882 return strdup([output UTF8String]);
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8883 }
a0aec9a56914 Font and color improvements... including implementing dw_window_set_font().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 738
diff changeset
8884 return NULL;
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8885 }
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8886
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
8887 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8888 * Destroys a window and all of it's children.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8889 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8890 * handle: The window handle to destroy.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8891 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8892 int API dw_window_destroy(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8893 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
8894 int _locked_by_me = FALSE;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
8895 DW_LOCAL_POOL_IN;
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
8896 DW_MUTEX_LOCK;
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8897 id object = handle;
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8898
1375
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8899 /* Handle destroying a top-level window */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8900 if([ object isKindOfClass:[ NSWindow class ] ])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8901 {
1313
9f12bc79924b Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1312
diff changeset
8902 DWWindow *window = handle;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8903 [window close];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8904 }
1375
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8905 /* Handle removing menu items from menus */
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8906 else if([ object isKindOfClass:[NSMenuItem class]])
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8907 {
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8908 NSMenu *menu = [object menu];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8909
1376
52bbb1acce61 Don't release the menu item when destroying it on Mac... causes crashes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1375
diff changeset
8910 [menu removeItem:object];
1375
611893219ba9 Implemented dw_menu_delete_item() on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1340
diff changeset
8911 }
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8912 /* Handle destroying a control or box */
1664
4ec0bce77f70 Fix dw_window_destroy() failing on splitbars and possibly other widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1654
diff changeset
8913 else if([object isKindOfClass:[NSView class]] || [object isKindOfClass:[NSControl class]])
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8914 {
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8915 DWBox *parent = (DWBox *)[object superview];
983
6abf763838c6 Allow checboxes and other "buttons" to have a blank title instead of the default "Button"
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 982
diff changeset
8916
6abf763838c6 Allow checboxes and other "buttons" to have a blank title instead of the default "Button"
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 982
diff changeset
8917 /* Some controls are embedded in scrollviews...
979
f6234f870e81 Attempt at fixing dw_window_destroy() for controls that are embedded in scrollviews on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 957
diff changeset
8918 * so get the parent of the scrollview in that case.
f6234f870e81 Attempt at fixing dw_window_destroy() for controls that are embedded in scrollviews on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 957
diff changeset
8919 */
1549
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
8920 if(([object isKindOfClass:[NSTableView class]] || [object isMemberOfClass:[DWMLE class]])
ca6be9c48fff Implemented auto-sizing containers on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1543
diff changeset
8921 && [parent isMemberOfClass:[NSClipView class]])
982
a4425bb24b77 Fixed dw_window_destroy() on container and trees... there are multiple parts to scrollviews aparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 981
diff changeset
8922 {
a4425bb24b77 Fixed dw_window_destroy() on container and trees... there are multiple parts to scrollviews aparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 981
diff changeset
8923 object = [parent superview];
980
94dde9b3dfc0 Ok so we need to set the object to be the right value in this case so it gets removed from the proper view on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 979
diff changeset
8924 parent = (DWBox *)[object superview];
979
f6234f870e81 Attempt at fixing dw_window_destroy() for controls that are embedded in scrollviews on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 957
diff changeset
8925 }
940
b5ae9cf15f68 Fix for returning wrong extension in _dw_get_image_extension; only worked for .ico files
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 939
diff changeset
8926
1099
d1cea9be1436 Fixed dw_window_destroy() with groupboxes on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1098
diff changeset
8927 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]])
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8928 {
1671
d5f39d32c4da Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1664
diff changeset
8929 id window = [object window];
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8930 Box *thisbox = [parent box];
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8931 int z, index = -1;
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8932 Item *tmpitem = NULL, *thisitem = thisbox->items;
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8933
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8934 if(!thisitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8935 thisbox->count = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8936
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8937 for(z=0;z<thisbox->count;z++)
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8938 {
982
a4425bb24b77 Fixed dw_window_destroy() on container and trees... there are multiple parts to scrollviews aparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 981
diff changeset
8939 if(thisitem[z].hwnd == object)
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8940 index = z;
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8941 }
940
b5ae9cf15f68 Fix for returning wrong extension in _dw_get_image_extension; only worked for .ico files
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 939
diff changeset
8942
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8943 if(index == -1)
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8944 {
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8945 DW_MUTEX_UNLOCK;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
8946 DW_LOCAL_POOL_OUT;
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8947 return 0;
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8948 }
940
b5ae9cf15f68 Fix for returning wrong extension in _dw_get_image_extension; only worked for .ico files
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 939
diff changeset
8949
982
a4425bb24b77 Fixed dw_window_destroy() on container and trees... there are multiple parts to scrollviews aparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 981
diff changeset
8950 [object removeFromSuperview];
1041
6a57bf20d8f9 Return displayName property instead of fontName property in dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1040
diff changeset
8951
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8952 if(thisbox->count > 1)
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8953 {
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8954 tmpitem = calloc(sizeof(Item), (thisbox->count-1));
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8955
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8956 /* Copy all but the current entry to the new list */
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8957 for(z=0;z<index;z++)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8958 {
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8959 tmpitem[z] = thisitem[z];
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8960 }
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8961 for(z=index+1;z<thisbox->count;z++)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8962 {
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8963 tmpitem[z-1] = thisitem[z];
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8964 }
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8965 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8966
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8967 thisbox->items = tmpitem;
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8968 if(thisitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8969 free(thisitem);
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8970 if(tmpitem)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8971 thisbox->count--;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8972 else
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
8973 thisbox->count = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
8974
1654
3d4066aab4e0 Fixed windows not automatically redrawing when removing items from a layout
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1652
diff changeset
8975 /* Queue a redraw on the top-level window */
3d4066aab4e0 Fixed windows not automatically redrawing when removing items from a layout
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1652
diff changeset
8976 _dw_redraw(window, TRUE);
937
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8977 }
83aceaaef6ed Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 936
diff changeset
8978 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
8979 DW_MUTEX_UNLOCK;
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
8980 DW_LOCAL_POOL_OUT;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
8981 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8982 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8983
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8984 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8985 * Gets the text used for a given window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8986 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8987 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8988 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8989 * text: The text associsated with a given window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8990 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8991 char * API dw_window_get_text(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8992 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
8993 id object = _text_handle(handle);
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
8994
808
c0641a6d4258 Similar fix for dw_window_get_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 807
diff changeset
8995 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ])
c0641a6d4258 Similar fix for dw_window_get_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 807
diff changeset
8996 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
8997 id window = object;
808
c0641a6d4258 Similar fix for dw_window_get_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 807
diff changeset
8998 NSString *nsstr = [ window title];
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
8999
808
c0641a6d4258 Similar fix for dw_window_get_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 807
diff changeset
9000 return strdup([ nsstr UTF8String ]);
c0641a6d4258 Similar fix for dw_window_get_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 807
diff changeset
9001 }
c0641a6d4258 Similar fix for dw_window_get_text().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 807
diff changeset
9002 else if([ object isKindOfClass:[ NSControl class ] ])
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9003 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
9004 NSControl *control = object;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9005 NSString *nsstr = [ control stringValue];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9006
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9007 return strdup([ nsstr UTF8String ]);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9008 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9009 return NULL;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9010 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9011
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9012 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9013 * Sets the text used for a given window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9014 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9015 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9016 * text: The text associsated with a given window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9017 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9018 void API dw_window_set_text(HWND handle, char *text)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9019 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
9020 id object = _text_handle(handle);
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
9021
807
f7016a38bedd Fix for dw_window_set_text() on buttons not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 806
diff changeset
9022 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ])
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
9023 [object setTitle:[ NSString stringWithUTF8String:text ]];
807
f7016a38bedd Fix for dw_window_set_text() on buttons not working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 806
diff changeset
9024 else if([ object isKindOfClass:[ NSControl class ] ])
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9025 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
9026 NSControl *control = object;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9027 [control setStringValue:[ NSString stringWithUTF8String:text ]];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9028 }
953
2dfc06afc7d3 Support dw_window_set_text() for groupboxes
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 952
diff changeset
9029 else if([object isMemberOfClass:[DWGroupBox class]])
2dfc06afc7d3 Support dw_window_set_text() for groupboxes
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 952
diff changeset
9030 {
1772
5e16351b01d2 Experimental change to use NSBox to draw border of status text widgets on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1771
diff changeset
9031 DWGroupBox *groupbox = object;
953
2dfc06afc7d3 Support dw_window_set_text() for groupboxes
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 952
diff changeset
9032 [groupbox setTitle:[NSString stringWithUTF8String:text]];
2dfc06afc7d3 Support dw_window_set_text() for groupboxes
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 952
diff changeset
9033 }
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
9034 else
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
9035 return;
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
9036 /* If we changed the text... */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
9037 Item *item = _box_item(handle);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9038
1410
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
9039 /* Check to see if any of the sizes need to be recalculated */
c607fd86e5c2 Initial code on the Mac to automatically calculate widget required sizes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1400
diff changeset
9040 if(item && (item->origwidth == -1 || item->origheight == -1))
1422
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
9041 {
1792
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9042 int newwidth, newheight;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9043
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9044 _control_size(handle, &newwidth, &newheight);
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9045
1792
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9046 /* Only update the item and redraw the window if it changed */
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9047 if((item->origwidth == -1 && item->width != newwidth) ||
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9048 (item->origheight == -1 && item->height != newheight))
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9049 {
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9050 if(item->origwidth == -1)
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9051 item->width = newwidth;
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9052 if(item->origheight == -1)
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9053 item->height = newheight;
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9054 /* Queue a redraw on the top-level window */
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9055 _dw_redraw([object window], TRUE);
b0bdec1b820c Similar fixes to the Mac one on OS/2 and Windows....
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1791
diff changeset
9056 }
1422
131bedf41332 Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1421
diff changeset
9057 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9058 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9059
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9060 /*
1389
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9061 * Sets the text used for a given window's floating bubble help.
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9062 * Parameters:
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9063 * handle: Handle to the window (widget).
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9064 * bubbletext: The text in the floating bubble tooltip.
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9065 */
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9066 void API dw_window_set_tooltip(HWND handle, char *bubbletext)
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9067 {
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9068 id object = handle;
1400
ccd383e11ff8 Allow removing of tooltips by passing NULL or "" and prevent double tooltips on some platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1396
diff changeset
9069 if(bubbletext && *bubbletext)
ccd383e11ff8 Allow removing of tooltips by passing NULL or "" and prevent double tooltips on some platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1396
diff changeset
9070 [object setToolTip:[NSString stringWithUTF8String:bubbletext]];
ccd383e11ff8 Allow removing of tooltips by passing NULL or "" and prevent double tooltips on some platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1396
diff changeset
9071 else
ccd383e11ff8 Allow removing of tooltips by passing NULL or "" and prevent double tooltips on some platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1396
diff changeset
9072 [object setToolTip:nil];
1389
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9073 }
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9074
0512fbb08abf Added dw_window_set_tooltip() for adding bubble help to most controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1385
diff changeset
9075 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9076 * Disables given window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9077 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9078 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9079 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9080 void API dw_window_disable(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9081 {
800
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9082 id object = handle;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
9083
800
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9084 if([object isMemberOfClass:[NSScrollView class]])
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9085 {
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9086 NSScrollView *sv = handle;
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9087 object = [sv documentView];
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9088 }
1277
107e38a29eeb Allow dw_window_enable/disable() to work on menu items on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1275
diff changeset
9089 if([object isKindOfClass:[NSControl class]] || [object isKindOfClass:[NSMenuItem class]])
107e38a29eeb Allow dw_window_enable/disable() to work on menu items on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1275
diff changeset
9090 {
107e38a29eeb Allow dw_window_enable/disable() to work on menu items on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1275
diff changeset
9091 [object setEnabled:NO];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9092 }
800
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9093 if([object isKindOfClass:[NSTextView class]])
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9094 {
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9095 NSTextView *mle = object;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
9096
800
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9097 [mle setEditable:NO];
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9098 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9099 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9100
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9101 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9102 * Enables given window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9103 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9104 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9105 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9106 void API dw_window_enable(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9107 {
800
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9108 id object = handle;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
9109
800
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9110 if([object isMemberOfClass:[NSScrollView class]])
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9111 {
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9112 NSScrollView *sv = handle;
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9113 object = [sv documentView];
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9114 }
1277
107e38a29eeb Allow dw_window_enable/disable() to work on menu items on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1275
diff changeset
9115 if([object isKindOfClass:[NSControl class]] || [object isKindOfClass:[NSMenuItem class]])
107e38a29eeb Allow dw_window_enable/disable() to work on menu items on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1275
diff changeset
9116 {
107e38a29eeb Allow dw_window_enable/disable() to work on menu items on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1275
diff changeset
9117 [object setEnabled:YES];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9118 }
800
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9119 if([object isKindOfClass:[NSTextView class]])
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9120 {
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9121 NSTextView *mle = object;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
9122
800
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9123 [mle setEditable:YES];
e5a0a1a3ee03 dw_window_enable() and dw_window_disable() now function as expected on MLE controls.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 799
diff changeset
9124 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9125 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9126
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9127 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9128 * Sets the bitmap used for a given static window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9129 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9130 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9131 * id: An ID to be used to specify the icon,
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9132 * (pass 0 if you use the filename param)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9133 * filename: a path to a file (Bitmap on OS/2 or
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9134 * Windows and a pixmap on Unix, pass
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9135 * NULL if you use the id param)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9136 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
9137 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, char *data, int len)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9138 {
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9139 id object = handle;
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9140
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9141 if([ object isKindOfClass:[ NSImageView class ] ] || [ object isKindOfClass:[ NSButton class ]])
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9142 {
1719
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9143 if(data)
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9144 {
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9145 DW_LOCAL_POOL_IN;
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9146 NSData *thisdata = [NSData dataWithBytes:data length:len];
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9147 NSImage *pixmap = [[[NSImage alloc] initWithData:thisdata] autorelease];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9148
1719
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9149 if(pixmap)
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9150 {
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9151 [object setImage:pixmap];
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9152 [pixmap release];
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9153 }
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9154 /* If we changed the bitmap... */
1719
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9155 Item *item = _box_item(handle);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9156
1719
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9157 /* Check to see if any of the sizes need to be recalculated */
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9158 if(item && (item->origwidth == -1 || item->origheight == -1))
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9159 {
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9160 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
1719
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9161 /* Queue a redraw on the top-level window */
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9162 _dw_redraw([object window], TRUE);
1719
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9163 }
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9164 DW_LOCAL_POOL_OUT;
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9165 }
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9166 else
032c3388dda6 Fix dw_window_set_bitmap_from_data() not using the resource ID if data is NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1713
diff changeset
9167 dw_window_set_bitmap(handle, cid, NULL);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9168 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9169 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9170
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9171 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9172 * Sets the bitmap used for a given static window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9173 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9174 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9175 * id: An ID to be used to specify the icon,
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9176 * (pass 0 if you use the filename param)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9177 * filename: a path to a file (Bitmap on OS/2 or
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9178 * Windows and a pixmap on Unix, pass
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9179 * NULL if you use the id param)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9180 */
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
9181 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9182 {
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9183 id object = handle;
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
9184 DW_LOCAL_POOL_IN;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9185
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9186 if([ object isKindOfClass:[ NSImageView class ] ] || [ object isKindOfClass:[ NSButton class ]])
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9187 {
745
d29fb0d5b291 Fixes for font handling on pixmaps... it needs to use the associated render control to get the fonts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 744
diff changeset
9188 NSImage *bitmap = nil;
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9189
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
9190 if(filename)
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
9191 {
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9192 char *ext = _dw_get_image_extension( filename );
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9193 NSString *nstr = [ NSString stringWithUTF8String:filename ];
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9194
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9195 bitmap = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9196
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9197 if(!bitmap && ext)
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9198 {
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9199 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9200 bitmap = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9201 }
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9202 }
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9203 if(!bitmap && resid > 0 && resid < 65536)
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
9204 {
1713
c836c6c33d8e Create an internal _dw_icon_load() which does not resize the image on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1712
diff changeset
9205 bitmap = _dw_icon_load(resid);
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
9206 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9207
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
9208 if(bitmap)
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
9209 {
1821
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9210 [object setImage:bitmap];
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9211
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9212 /* If we changed the bitmap... */
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9213 Item *item = _box_item(handle);
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9214
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9215 /* Check to see if any of the sizes need to be recalculated */
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9216 if(item && (item->origwidth == -1 || item->origheight == -1))
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9217 {
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9218 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9219 /* Queue a redraw on the top-level window */
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9220 _dw_redraw([object window], TRUE);
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9221 }
69f9aa1e1b1e Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1819
diff changeset
9222 [bitmap release];
675
48f8efba898f Filled in most of the remaining MLE and container functions... the remaining few
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 674
diff changeset
9223 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9224 }
1580
a51397ea24bf Added local auto-release macros on Mac to allow us to prevent leaks
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1574
diff changeset
9225 DW_LOCAL_POOL_OUT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9226 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9227
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9228 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9229 * Sets the icon used for a given window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9230 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9231 * handle: Handle to the window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9232 * id: An ID to be used to specify the icon.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9233 */
672
388f2a48aaae Missed one function to typedef. Fixed errors in the test program and switched to using
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 671
diff changeset
9234 void API dw_window_set_icon(HWND handle, HICN icon)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9235 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9236 /* This isn't needed, it is loaded from the bundle */
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9237 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9238
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9239 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9240 * Gets the child window handle with specified ID.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9241 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9242 * handle: Handle to the parent window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9243 * id: Integer ID of the child.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9244 */
685
314a12dccd20 Cleanups for conflicts with "id" which is a keyword in Objective-C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 684
diff changeset
9245 HWND API dw_window_from_id(HWND handle, int cid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9246 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9247 NSObject *object = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9248 NSView *view = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9249 if([ object isKindOfClass:[ NSWindow class ] ])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9250 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9251 NSWindow *window = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9252 view = [window contentView];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9253 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9254 return [view viewWithTag:cid];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9255 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9256
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9257 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9258 * Minimizes or Iconifies a top-level window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9259 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9260 * handle: The window handle to minimize.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9261 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9262 int API dw_window_minimize(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9263 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9264 NSWindow *window = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9265 [window miniaturize:nil];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9266 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9267 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9268
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9269 /* Causes entire window to be invalidated and redrawn.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9270 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9271 * handle: Toplevel window handle to be redrawn.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9272 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9273 void API dw_window_redraw(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9274 {
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
9275 DWWindow *window = handle;
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
9276 [window setRedraw:YES];
941
18f194e1d71d dw_window_redraw() should relayout the window in addition to flushing the buffer on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 940
diff changeset
9277 [[window contentView] showWindow];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9278 [window flushWindow];
1101
d7eafaa054ab Added support for dw_window_redraw() causing splitbar panes to redraw without
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1100
diff changeset
9279 [window setRedraw:NO];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9280 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9281
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9282 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9283 * Makes the window topmost.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9284 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9285 * handle: The window handle to make topmost.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9286 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9287 int API dw_window_raise(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9288 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9289 NSWindow *window = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9290 [window orderFront:nil];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9291 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9292 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9293
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9294 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9295 * Makes the window bottommost.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9296 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9297 * handle: The window handle to make bottommost.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9298 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9299 int API dw_window_lower(HWND handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9300 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9301 NSWindow *window = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9302 [window orderBack:nil];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9303 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9304 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9305
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9306 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9307 * Sets the size of a given window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9308 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9309 * handle: Window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9310 * width: New width in pixels.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9311 * height: New height in pixels.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9312 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9313 void API dw_window_set_size(HWND handle, ULONG width, ULONG height)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9314 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
9315 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
9316 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9317 NSObject *object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9318
1494
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9319 if([ object isMemberOfClass:[ DWWindow class ] ])
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9320 {
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9321 DWWindow *window = handle;
1438
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9322 Box *thisbox;
1478
7216f4301364 Fix mixing frame and content sizes on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1474
diff changeset
9323 NSRect content, frame = NSMakeRect(0, 0, width, height);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9324
1478
7216f4301364 Fix mixing frame and content sizes on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1474
diff changeset
9325 /* Convert the external frame size to internal content size */
7216f4301364 Fix mixing frame and content sizes on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1474
diff changeset
9326 content = [NSWindow contentRectForFrameRect:frame styleMask:[window styleMask]];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9327
1438
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9328 /*
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9329 * The following is an attempt to dynamically size a window based on the size of its
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9330 * children before realization. Only applicable when width or height is less than one.
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9331 */
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9332 if((width < 1 || height < 1) && (thisbox = [[window contentView] box]))
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9333 {
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9334 int depth = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9335
1438
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9336 /* Calculate space requirements */
1446
0d4fdf646caf Fix clang integer conversion warning on 64bit Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1442
diff changeset
9337 _resize_box(thisbox, &depth, (int)width, (int)height, 1);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9338
1531
783a464afab2 Added window and box support to dw_window_get_preferred_size() on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1530
diff changeset
9339 /* Update components that need auto-sizing */
1478
7216f4301364 Fix mixing frame and content sizes on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1474
diff changeset
9340 if(width < 1) content.size.width = thisbox->minwidth;
7216f4301364 Fix mixing frame and content sizes on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1474
diff changeset
9341 if(height < 1) content.size.height = thisbox->minheight;
1438
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9342 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9343
1438
bde7ebced556 Initial layout engine 2.0 for Windows and OS/2...Plus some updates for the Mac code...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1437
diff changeset
9344 /* Finally set the size */
1478
7216f4301364 Fix mixing frame and content sizes on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1474
diff changeset
9345 [window setContentSize:content.size];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9346 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
9347 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9348 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9349
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9350 /*
1429
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9351 * Gets the size the system thinks the widget should be.
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9352 * Parameters:
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9353 * handle: Window handle of the item to be back.
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9354 * width: Width in pixels of the item or NULL if not needed.
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9355 * height: Height in pixels of the item or NULL if not needed.
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9356 */
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9357 void API dw_window_get_preferred_size(HWND handle, int *width, int *height)
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9358 {
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9359 id object = handle;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9360
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9361 if([object isMemberOfClass:[DWWindow class]])
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9362 {
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9363 Box *thisbox;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9364
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9365 if((thisbox = [[object contentView] box]))
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9366 {
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9367 int depth = 0;
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9368 NSRect frame;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9369
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9370 /* Calculate space requirements */
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9371 _resize_box(thisbox, &depth, 0, 0, 1);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9372
1531
783a464afab2 Added window and box support to dw_window_get_preferred_size() on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1530
diff changeset
9373 /* Figure out the border size */
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9374 frame = [NSWindow frameRectForContentRect:NSMakeRect(0, 0, thisbox->minwidth, thisbox->minheight) styleMask:[object styleMask]];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9375
1531
783a464afab2 Added window and box support to dw_window_get_preferred_size() on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1530
diff changeset
9376 /* Return what was requested */
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9377 if(width) *width = frame.size.width;
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9378 if(height) *height = frame.size.height;
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9379 }
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9380 }
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9381 else if([object isMemberOfClass:[DWBox class]])
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9382 {
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9383 Box *thisbox;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9384
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9385 if((thisbox = [object box]))
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9386 {
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9387 int depth = 0;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9388
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9389 /* Calculate space requirements */
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9390 _resize_box(thisbox, &depth, 0, 0, 1);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9391
1531
783a464afab2 Added window and box support to dw_window_get_preferred_size() on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1530
diff changeset
9392 /* Return what was requested */
1530
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9393 if(width) *width = thisbox->minwidth;
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9394 if(height) *height = thisbox->minheight;
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9395 }
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9396 }
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9397 else
eecfceaf581f On Mac allow dw_window_get_preferred_size() to work on windows and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1529
diff changeset
9398 _control_size(handle, width, height);
1429
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9399 }
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9400
fbaec6e5df63 Added dw_window_get_preferred_size() which attempts to determine the size the system wants for the widget. This is useful when creating nice looking layouts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1425
diff changeset
9401 /*
1474
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9402 * Sets the gravity of a given window (widget).
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9403 * Gravity controls which corner of the screen and window the position is relative to.
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9404 * Parameters:
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9405 * handle: Window (widget) handle.
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9406 * horz: DW_GRAV_LEFT (default), DW_GRAV_RIGHT or DW_GRAV_CENTER.
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9407 * vert: DW_GRAV_TOP (default), DW_GRAV_BOTTOM or DW_GRAV_CENTER.
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9408 */
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9409 void API dw_window_set_gravity(HWND handle, int horz, int vert)
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9410 {
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9411 dw_window_set_data(handle, "_dw_grav_horz", DW_INT_TO_POINTER(horz));
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9412 dw_window_set_data(handle, "_dw_grav_vert", DW_INT_TO_POINTER(vert));
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9413 }
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9414
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9415 /* Convert the coordinates based on gravity */
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9416 void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height)
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9417 {
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9418 int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz"));
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9419 int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert"));
1513
def1ca619ba2 Use the screen of the window when possible on Mac instead of the main screen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1502
diff changeset
9420 id object = handle;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9421
1474
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9422 /* Do any gravity calculations */
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9423 if(horz || (vert & 0xf) != DW_GRAV_BOTTOM)
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9424 {
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9425 long newx = *x, newy = *y;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9426
1474
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9427 /* Handle horizontal center gravity */
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9428 if((horz & 0xf) == DW_GRAV_CENTER)
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9429 newx += ((dw_screen_width() / 2) - (width / 2));
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9430 /* Handle right gravity */
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9431 else if((horz & 0xf) == DW_GRAV_RIGHT)
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9432 newx = dw_screen_width() - width - *x;
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9433 /* Handle vertical center gravity */
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9434 if((vert & 0xf) == DW_GRAV_CENTER)
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9435 newy += ((dw_screen_height() / 2) - (height / 2));
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9436 else if((vert & 0xf) == DW_GRAV_TOP)
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9437 newy = dw_screen_height() - height - *y;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9438
1474
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9439 /* Save the new values */
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9440 *x = newx;
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9441 *y = newy;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9442 }
1492
1608c2a9c2b8 Initial attempt at gravity obstacles on Mac.... doesn't work was trying to debug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1490
diff changeset
9443 /* Adjust the values to avoid Dock/Menubar if requested */
1494
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9444 if((horz | vert) & DW_GRAV_OBSTACLES)
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9445 {
1513
def1ca619ba2 Use the screen of the window when possible on Mac instead of the main screen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1502
diff changeset
9446 NSRect visiblerect = [[object screen] visibleFrame];
def1ca619ba2 Use the screen of the window when possible on Mac instead of the main screen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1502
diff changeset
9447 NSRect totalrect = [[object screen] frame];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9448
1494
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9449 if(horz & DW_GRAV_OBSTACLES)
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9450 {
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9451 if((horz & 0xf) == DW_GRAV_LEFT)
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9452 *x += visiblerect.origin.x;
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9453 else if((horz & 0xf) == DW_GRAV_RIGHT)
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9454 *x -= (totalrect.origin.x + totalrect.size.width) - (visiblerect.origin.x + visiblerect.size.width);
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9455 }
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9456 if(vert & DW_GRAV_OBSTACLES)
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9457 {
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9458 if((vert & 0xf) == DW_GRAV_BOTTOM)
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9459 *y += visiblerect.origin.y;
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9460 else if((vert & 0xf) == DW_GRAV_TOP)
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9461 *y -= (totalrect.origin.y + totalrect.size.height) - (visiblerect.origin.y + visiblerect.size.height);
cf960e266444 Fixes for gravity obstacles on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1492
diff changeset
9462 }
1492
1608c2a9c2b8 Initial attempt at gravity obstacles on Mac.... doesn't work was trying to debug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1490
diff changeset
9463 }
1474
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9464 }
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9465
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9466 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9467 * Sets the position of a given window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9468 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9469 * handle: Window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9470 * x: X location from the bottom left.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9471 * y: Y location from the bottom left.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9472 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9473 void API dw_window_set_pos(HWND handle, LONG x, LONG y)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9474 {
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
9475 int _locked_by_me = FALSE;
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
9476 DW_MUTEX_LOCK;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9477 NSObject *object = handle;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9478
1497
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
9479 if([ object isMemberOfClass:[ DWWindow class ] ])
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
9480 {
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
9481 DWWindow *window = handle;
1474
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9482 NSPoint point;
1498
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9483 NSSize size = [[window contentView] frame].size;
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9484
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9485 /* Can't position an unsized window, so attempt to auto-size */
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9486 if(size.width <= 1 || size.height <= 1)
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9487 {
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9488 /* Determine the contents size */
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9489 dw_window_set_size(handle, 0, 0);
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9490 }
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9491
f8b4d6075cac Added auto-size support during dw_window_set_pos() on OS/2, Mac and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1497
diff changeset
9492 size = [window frame].size;
1474
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9493 _handle_gravity(handle, &x, &y, (unsigned long)size.width, (unsigned long)size.height);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9494
1474
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9495 point.x = x;
cd3d7e341467 Initial implementation of dw_window_set_gravity() on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1457
diff changeset
9496 point.y = y;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9497
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9498 [window setFrameOrigin:point];
1497
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
9499 /* Position set manually... don't auto-position */
99a53823079f On Mac lets just use the shown flag and not worry about the actual window position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1494
diff changeset
9500 [window setShown:YES];
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9501 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
9502 DW_MUTEX_UNLOCK;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9503 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9504
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9505 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9506 * Sets the position and size of a given window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9507 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9508 * handle: Window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9509 * x: X location from the bottom left.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9510 * y: Y location from the bottom left.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9511 * width: Width of the widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9512 * height: Height of the widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9513 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9514 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9515 {
947
c9f6ba940453 On window sizes we need to flip the origin point on the frame too on the Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 946
diff changeset
9516 dw_window_set_size(handle, width, height);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9517 dw_window_set_pos(handle, x, y);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9518 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9519
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9520 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9521 * Gets the position and size of a given window (widget).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9522 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9523 * handle: Window (widget) handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9524 * x: X location from the bottom left.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9525 * y: Y location from the bottom left.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9526 * width: Width of the widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9527 * height: Height of the widget.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9528 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9529 void API dw_window_get_pos_size(HWND handle, LONG *x, LONG *y, ULONG *width, ULONG *height)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9530 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9531 NSObject *object = handle;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9532
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9533 if([ object isKindOfClass:[ NSWindow class ] ])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9534 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9535 NSWindow *window = handle;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9536 NSRect rect = [window frame];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9537 if(x)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9538 *x = rect.origin.x;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9539 if(y)
1513
def1ca619ba2 Use the screen of the window when possible on Mac instead of the main screen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1502
diff changeset
9540 *y = [[window screen] frame].size.height - rect.origin.y - rect.size.height;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9541 if(width)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9542 *width = rect.size.width;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9543 if(height)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9544 *height = rect.size.height;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9545 return;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9546 }
951
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9547 else if([ object isKindOfClass:[ NSControl class ] ])
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9548 {
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9549 NSControl *control = handle;
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9550 NSRect rect = [control frame];
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9551 if(x)
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9552 *x = rect.origin.x;
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9553 if(y)
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9554 *y = rect.origin.y;
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9555 if(width)
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9556 *width = rect.size.width;
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9557 if(height)
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9558 *height = rect.size.height;
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9559 return;
7193401d139a Added support for dw_window_get_pos_size() to work on individual controls on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 950
diff changeset
9560 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9561 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9562
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9563 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9564 * Returns the width of the screen.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9565 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9566 int API dw_screen_width(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9567 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9568 NSRect screenRect = [[NSScreen mainScreen] frame];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9569 return screenRect.size.width;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9570 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9571
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9572 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9573 * Returns the height of the screen.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9574 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9575 int API dw_screen_height(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9576 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9577 NSRect screenRect = [[NSScreen mainScreen] frame];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9578 return screenRect.size.height;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9579 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9580
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9581 /* This should return the current color depth */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9582 unsigned long API dw_color_depth_get(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9583 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9584 NSWindowDepth screenDepth = [[NSScreen mainScreen] depth];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9585 return NSBitsPerPixelFromDepth(screenDepth);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9586 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9587
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9588 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9589 * Returns some information about the current operating environment.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9590 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9591 * env: Pointer to a DWEnv struct.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9592 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9593 void dw_environment_query(DWEnv *env)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9594 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9595 struct utsname name;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9596
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9597 uname(&name);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9598 strcpy(env->osName, "MacOS");
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9599
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9600 strcpy(env->buildDate, __DATE__);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9601 strcpy(env->buildTime, __TIME__);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9602 env->DWMajorVersion = DW_MAJOR_VERSION;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9603 env->DWMinorVersion = DW_MINOR_VERSION;
1160
924c8087a755 Attempt to use the subversion revision number as the sub version number.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1158
diff changeset
9604 #ifdef VER_REV
924c8087a755 Attempt to use the subversion revision number as the sub version number.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1158
diff changeset
9605 env->DWSubVersion = VER_REV;
924c8087a755 Attempt to use the subversion revision number as the sub version number.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1158
diff changeset
9606 #else
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9607 env->DWSubVersion = DW_SUB_VERSION;
1160
924c8087a755 Attempt to use the subversion revision number as the sub version number.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1158
diff changeset
9608 #endif
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9609
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
9610 env->MajorVersion = DWOSMajor;
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
9611 env->MinorVersion = DWOSMinor;
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
9612 env->MajorBuild = DWOSBuild;
809
1ef0f4c03c14 MinorBuild was being left uninitialized.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 808
diff changeset
9613 env->MinorBuild = 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9614 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9615
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9616 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9617 * Emits a beep.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9618 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9619 * freq: Frequency.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9620 * dur: Duration.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9621 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9622 void API dw_beep(int freq, int dur)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9623 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9624 NSBeep();
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9625 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9626
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9627 /* Call this after drawing to the screen to make sure
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9628 * anything you have drawn is visible.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9629 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9630 void API dw_flush(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9631 {
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
9632 /* This may need to be thread specific */
699
b79300831495 Offload some drawing functions to the main thread to prevent focus deadlocks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 698
diff changeset
9633 [DWObj performSelectorOnMainThread:@selector(doFlush:) withObject:nil waitUntilDone:NO];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9634 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9635
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9636 /* Functions for managing the user data lists that are associated with
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9637 * a given window handle. Used in dw_window_set_data() and
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9638 * dw_window_get_data().
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9639 */
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9640 UserData *_find_userdata(UserData **root, char *varname)
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9641 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9642 UserData *tmp = *root;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9643
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9644 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9645 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9646 if(strcasecmp(tmp->varname, varname) == 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9647 return tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9648 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9649 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9650 return NULL;
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9651 }
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9652
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9653 int _new_userdata(UserData **root, char *varname, void *data)
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9654 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9655 UserData *new = _find_userdata(root, varname);
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9656
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9657 if(new)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9658 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9659 new->data = data;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9660 return TRUE;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9661 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9662 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9663 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9664 new = malloc(sizeof(UserData));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9665 if(new)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9666 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9667 new->varname = strdup(varname);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9668 new->data = data;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9669
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9670 new->next = NULL;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9671
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9672 if (!*root)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9673 *root = new;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9674 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9675 {
1303
ca02c24e80c9 Experimental change to menu code on Windows to allow dw_window_enable/disable to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1302
diff changeset
9676 UserData *prev = *root, *tmp = prev->next;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
9677
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9678 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9679 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9680 prev = tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9681 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9682 }
1303
ca02c24e80c9 Experimental change to menu code on Windows to allow dw_window_enable/disable to work on menu item handles.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1302
diff changeset
9683 prev->next = new;
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9684 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9685 return TRUE;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9686 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9687 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9688 return FALSE;
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9689 }
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9690
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9691 int _remove_userdata(UserData **root, char *varname, int all)
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9692 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9693 UserData *prev = NULL, *tmp = *root;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9694
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9695 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9696 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9697 if(all || strcasecmp(tmp->varname, varname) == 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9698 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9699 if(!prev)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9700 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9701 *root = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9702 free(tmp->varname);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9703 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9704 if(!all)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9705 return 0;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9706 tmp = *root;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9707 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9708 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9709 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9710 /* If all is true we should
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9711 * never get here.
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9712 */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9713 prev->next = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9714 free(tmp->varname);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9715 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9716 return 0;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9717 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9718 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9719 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9720 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9721 prev = tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9722 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9723 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9724 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9725 return 0;
651
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9726 }
270580896dac Filling in more class types.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 650
diff changeset
9727
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9728 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9729 * Add a named user data item to a window handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9730 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9731 * window: Window handle of signal to be called back.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9732 * dataname: A string pointer identifying which signal to be hooked.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9733 * data: User data to be passed to the handler function.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9734 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9735 void dw_window_set_data(HWND window, char *dataname, void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9736 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9737 id object = window;
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
9738 if([object isMemberOfClass:[DWWindow class]])
681
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9739 {
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9740 NSWindow *win = window;
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9741 object = [win contentView];
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9742 }
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9743 else if([object isMemberOfClass:[NSScrollView class]])
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
9744 {
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
9745 NSScrollView *sv = window;
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
9746 object = [sv documentView];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
9747 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9748 WindowData *blah = (WindowData *)[object userdata];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9749
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9750 if(!blah)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9751 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9752 if(!dataname)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9753 return;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9754
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9755 blah = calloc(1, sizeof(WindowData));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9756 [object setUserdata:blah];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9757 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9758
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9759 if(data)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9760 _new_userdata(&(blah->root), dataname, data);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9761 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9762 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9763 if(dataname)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9764 _remove_userdata(&(blah->root), dataname, FALSE);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9765 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9766 _remove_userdata(&(blah->root), NULL, TRUE);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9767 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9768 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9769
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9770 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9771 * Gets a named user data item to a window handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9772 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9773 * window: Window handle of signal to be called back.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9774 * dataname: A string pointer identifying which signal to be hooked.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9775 * data: User data to be passed to the handler function.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9776 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9777 void *dw_window_get_data(HWND window, char *dataname)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9778 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9779 id object = window;
894
d1d7e5c51860 Added a DWWindow subclass to trap key events on the main window for Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 891
diff changeset
9780 if([object isMemberOfClass:[DWWindow class]])
681
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9781 {
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9782 NSWindow *win = window;
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9783 object = [win contentView];
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9784 }
5fe12469c1fb Fix for dw_window_set/get_data() on a top-level window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 680
diff changeset
9785 else if([object isMemberOfClass:[NSScrollView class]])
676
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
9786 {
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
9787 NSScrollView *sv = window;
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
9788 object = [sv documentView];
9861d264925d MLE was missing the scrollbar. Fixes for getting and setting the position.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 675
diff changeset
9789 }
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9790 WindowData *blah = (WindowData *)[object userdata];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9791
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9792 if(blah && blah->root && dataname)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9793 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9794 UserData *ud = _find_userdata(&(blah->root), dataname);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9795 if(ud)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9796 return ud->data;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9797 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9798 return NULL;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9799 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9800
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
9801 #define DW_TIMER_MAX 64
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
9802 NSTimer *DWTimers[DW_TIMER_MAX];
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
9803
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9804 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9805 * Add a callback to a timer event.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9806 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9807 * interval: Milliseconds to delay between calls.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9808 * sigfunc: The pointer to the function to be used as the callback.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9809 * data: User data to be passed to the handler function.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9810 * Returns:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9811 * Timer ID for use with dw_timer_disconnect(), 0 on error.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9812 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9813 int API dw_timer_connect(int interval, void *sigfunc, void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9814 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9815 int z;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9816
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9817 for(z=0;z<DW_TIMER_MAX;z++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9818 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9819 if(!DWTimers[z])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9820 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9821 break;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9822 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9823 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9824
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9825 if(sigfunc && !DWTimers[z])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9826 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9827 NSTimeInterval seconds = (double)interval / 1000.0;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9828 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9829 _new_signal(0, thistimer, z+1, sigfunc, data);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9830 return z+1;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9831 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9832 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9833 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9834
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9835 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9836 * Removes timer callback.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9837 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9838 * id: Timer ID returned by dw_timer_connect().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9839 */
657
f31a47b055f8 Work (unfinished) on container objects.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 656
diff changeset
9840 void API dw_timer_disconnect(int timerid)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9841 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9842 SignalHandler *prev = NULL, *tmp = Root;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9843 NSTimer *thistimer;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9844
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9845 /* 0 is an invalid timer ID */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9846 if(timerid < 1 || !DWTimers[timerid-1])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9847 return;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9848
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9849 thistimer = DWTimers[timerid-1];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9850 DWTimers[timerid-1] = nil;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9851
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9852 [thistimer invalidate];
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9853
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9854 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9855 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9856 if(tmp->id == timerid && tmp->window == thistimer)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9857 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9858 if(prev)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9859 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9860 prev->next = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9861 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9862 tmp = prev->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9863 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9864 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9865 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9866 Root = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9867 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9868 tmp = Root;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9869 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9870 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9871 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9872 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9873 prev = tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9874 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9875 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9876 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9877 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9878
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9879 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9880 * Add a callback to a window event.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9881 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9882 * window: Window handle of signal to be called back.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9883 * signame: A string pointer identifying which signal to be hooked.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9884 * sigfunc: The pointer to the function to be used as the callback.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9885 * data: User data to be passed to the handler function.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9886 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9887 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9888 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9889 ULONG message = 0, msgid = 0;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9890
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9891 if(window && signame && sigfunc)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9892 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9893 if((message = _findsigmessage(signame)) != 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9894 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9895 _new_signal(message, window, (int)msgid, sigfunc, data);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9896 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9897 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9898 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9899
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9900 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9901 * Removes callbacks for a given window with given name.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9902 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9903 * window: Window handle of callback to be removed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9904 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9905 void API dw_signal_disconnect_by_name(HWND window, char *signame)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9906 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9907 SignalHandler *prev = NULL, *tmp = Root;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9908 ULONG message;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9909
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9910 if(!window || !signame || (message = _findsigmessage(signame)) == 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9911 return;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9912
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9913 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9914 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9915 if(tmp->window == window && tmp->message == message)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9916 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9917 if(prev)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9918 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9919 prev->next = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9920 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9921 tmp = prev->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9922 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9923 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9924 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9925 Root = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9926 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9927 tmp = Root;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9928 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9929 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9930 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9931 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9932 prev = tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9933 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9934 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9935 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9936 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9937
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9938 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9939 * Removes all callbacks for a given window.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9940 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9941 * window: Window handle of callback to be removed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9942 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9943 void API dw_signal_disconnect_by_window(HWND window)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9944 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9945 SignalHandler *prev = NULL, *tmp = Root;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9946
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9947 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9948 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9949 if(tmp->window == window)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9950 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9951 if(prev)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9952 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9953 prev->next = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9954 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9955 tmp = prev->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9956 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9957 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9958 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9959 Root = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9960 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9961 tmp = Root;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9962 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9963 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9964 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9965 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9966 prev = tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9967 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9968 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9969 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9970 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9971
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9972 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9973 * Removes all callbacks for a given window with specified data.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9974 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9975 * window: Window handle of callback to be removed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9976 * data: Pointer to the data to be compared against.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9977 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9978 void API dw_signal_disconnect_by_data(HWND window, void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9979 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9980 SignalHandler *prev = NULL, *tmp = Root;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
9981
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9982 while(tmp)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9983 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9984 if(tmp->window == window && tmp->data == data)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9985 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9986 if(prev)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9987 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9988 prev->next = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9989 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9990 tmp = prev->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9991 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9992 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9993 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9994 Root = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9995 free(tmp);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9996 tmp = Root;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9997 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9998 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
9999 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10000 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10001 prev = tmp;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10002 tmp = tmp->next;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10003 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10004 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10005 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10006
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10007 void _my_strlwr(char *buf)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10008 {
1110
404b639f096b Minor typecast fixes for warnings reported by clang on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1102
diff changeset
10009 int z, len = (int)strlen(buf);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10010
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10011 for(z=0;z<len;z++)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10012 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10013 if(buf[z] >= 'A' && buf[z] <= 'Z')
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10014 buf[z] -= 'A' - 'a';
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10015 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10016 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10017
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10018 /* Open a shared library and return a handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10019 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10020 * name: Base name of the shared library.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10021 * handle: Pointer to a module handle,
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10022 * will be filled in with the handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10023 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10024 int dw_module_load(char *name, HMOD *handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10025 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10026 int len;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10027 char *newname;
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
10028 char errorbuf[1025];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10029
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10030
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10031 if(!handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10032 return -1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10033
1110
404b639f096b Minor typecast fixes for warnings reported by clang on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1102
diff changeset
10034 if((len = (int)strlen(name)) == 0)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10035 return -1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10036
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10037 /* Lenth + "lib" + ".dylib" + NULL */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10038 newname = malloc(len + 10);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10039
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10040 if(!newname)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10041 return -1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10042
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10043 sprintf(newname, "lib%s.dylib", name);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10044 _my_strlwr(newname);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10045
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10046 *handle = dlopen(newname, RTLD_NOW);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10047 if(*handle == NULL)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10048 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10049 strncpy(errorbuf, dlerror(), 1024);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10050 printf("%s\n", errorbuf);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10051 sprintf(newname, "lib%s.dylib", name);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10052 *handle = dlopen(newname, RTLD_NOW);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10053 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10054
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10055 free(newname);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10056
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10057 return (NULL == *handle) ? -1 : 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10058 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10059
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10060 /* Queries the address of a symbol within open handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10061 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10062 * handle: Module handle returned by dw_module_load()
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10063 * name: Name of the symbol you want the address of.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10064 * func: A pointer to a function pointer, to obtain
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10065 * the address.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10066 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10067 int dw_module_symbol(HMOD handle, char *name, void**func)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10068 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10069 if(!func || !name)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10070 return -1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10071
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10072 if(strlen(name) == 0)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10073 return -1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10074
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10075 *func = (void*)dlsym(handle, name);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10076 return (NULL == *func);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10077 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10078
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10079 /* Frees the shared library previously opened.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10080 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10081 * handle: Module handle returned by dw_module_load()
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10082 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10083 int dw_module_close(HMOD handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10084 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10085 if(handle)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10086 return dlclose(handle);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10087 return 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10088 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10089
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10090 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10091 * Returns the handle to an unnamed mutex semaphore.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10092 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10093 HMTX dw_mutex_new(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10094 {
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
10095 HMTX mutex = malloc(sizeof(pthread_mutex_t));
727
f190b5c2ce16 Fixed 2 errors in the tree select event handler. Also removed unused experimental code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 726
diff changeset
10096
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
10097 pthread_mutex_init(mutex, NULL);
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
10098 return mutex;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10099 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10100
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10101 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10102 * Closes a semaphore created by dw_mutex_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10103 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10104 * mutex: The handle to the mutex returned by dw_mutex_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10105 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10106 void dw_mutex_close(HMTX mutex)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10107 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10108 if(mutex)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10109 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10110 pthread_mutex_destroy(mutex);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10111 free(mutex);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10112 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10113 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10114
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10115 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10116 * Tries to gain access to the semaphore, if it can't it blocks.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10117 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10118 * mutex: The handle to the mutex returned by dw_mutex_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10119 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10120 void dw_mutex_lock(HMTX mutex)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10121 {
693
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10122 /* We need to handle locks from the main thread differently...
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
10123 * since we can't stop message processing... otherwise we
693
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10124 * will deadlock... so try to acquire the lock and continue
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10125 * processing messages in between tries.
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10126 */
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
10127 if(DWThread == pthread_self())
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
10128 {
693
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10129 while(pthread_mutex_trylock(mutex) != 0)
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10130 {
725
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
10131 /* Process any pending events */
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
10132 while(_dw_main_iteration([NSDate dateWithTimeIntervalSinceNow:0.01]))
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
10133 {
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
10134 /* Just loop */
4e09c92363df Experimental changes to dw_main_sleep() and dw_main_iteration() to hopefully solve some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 724
diff changeset
10135 }
693
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10136 }
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
10137 }
693
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10138 else
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
10139 {
693
2f21ee9d7c7b Experimental change for locking on the main thread... will be committing
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 692
diff changeset
10140 pthread_mutex_lock(mutex);
691
578bbfd8c904 Added initial thread synchronization code to stop the main loop when doing thread unsafe things.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 690
diff changeset
10141 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10142 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10143
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10144 /*
1158
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10145 * Tries to gain access to the semaphore.
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10146 * Parameters:
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10147 * mutex: The handle to the mutex returned by dw_mutex_new().
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10148 * Returns:
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10149 * DW_ERROR_NONE on success, DW_ERROR_TIMEOUT if it is already locked.
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10150 */
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10151 int API dw_mutex_trylock(HMTX mutex)
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10152 {
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10153 if(pthread_mutex_trylock(mutex) == 0)
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10154 return DW_ERROR_NONE;
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10155 return DW_ERROR_TIMEOUT;
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10156 }
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10157
f86f556ff29d Added dw_mutex_trylock() that functions like dw_mutex_lock() except
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1155
diff changeset
10158 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10159 * Reliquishes the access to the semaphore.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10160 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10161 * mutex: The handle to the mutex returned by dw_mutex_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10162 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10163 void dw_mutex_unlock(HMTX mutex)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10164 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10165 pthread_mutex_unlock(mutex);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10166 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10167
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10168 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10169 * Returns the handle to an unnamed event semaphore.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10170 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10171 HEV dw_event_new(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10172 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10173 HEV eve = (HEV)malloc(sizeof(struct _dw_unix_event));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10174
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10175 if(!eve)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10176 return NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10177
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10178 /* We need to be careful here, mutexes on Linux are
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10179 * FAST by default but are error checking on other
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10180 * systems such as FreeBSD and OS/2, perhaps others.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10181 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10182 pthread_mutex_init (&(eve->mutex), NULL);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10183 pthread_mutex_lock (&(eve->mutex));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10184 pthread_cond_init (&(eve->event), NULL);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10185
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10186 pthread_mutex_unlock (&(eve->mutex));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10187 eve->alive = 1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10188 eve->posted = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10189
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10190 return eve;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10191 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10192
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10193 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10194 * Resets a semaphore created by dw_event_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10195 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10196 * eve: The handle to the event returned by dw_event_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10197 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10198 int dw_event_reset (HEV eve)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10199 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10200 if(!eve)
986
87dc0f5f96d0 Fix return type of dw_listbox_selected() to be "int" instead of "unsigned int" to allow -1 return.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 983
diff changeset
10201 return DW_ERROR_NON_INIT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10202
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10203 pthread_mutex_lock (&(eve->mutex));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10204 pthread_cond_broadcast (&(eve->event));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10205 pthread_cond_init (&(eve->event), NULL);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10206 eve->posted = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10207 pthread_mutex_unlock (&(eve->mutex));
986
87dc0f5f96d0 Fix return type of dw_listbox_selected() to be "int" instead of "unsigned int" to allow -1 return.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 983
diff changeset
10208 return DW_ERROR_NONE;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10209 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10210
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10211 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10212 * Posts a semaphore created by dw_event_new(). Causing all threads
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10213 * waiting on this event in dw_event_wait to continue.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10214 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10215 * eve: The handle to the event returned by dw_event_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10216 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10217 int dw_event_post (HEV eve)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10218 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10219 if(!eve)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10220 return FALSE;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10221
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10222 pthread_mutex_lock (&(eve->mutex));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10223 pthread_cond_broadcast (&(eve->event));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10224 eve->posted = 1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10225 pthread_mutex_unlock (&(eve->mutex));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10226 return 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10227 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10228
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10229 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10230 * Waits on a semaphore created by dw_event_new(), until the
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10231 * event gets posted or until the timeout expires.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10232 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10233 * eve: The handle to the event returned by dw_event_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10234 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10235 int dw_event_wait(HEV eve, unsigned long timeout)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10236 {
1155
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10237 int rc;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10238
1155
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10239 if(!eve)
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10240 return DW_ERROR_NON_INIT;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10241
1202
5c1a01c6384d Think we need to check the posted state inside the mutex...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1201
diff changeset
10242 pthread_mutex_lock (&(eve->mutex));
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10243
1155
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10244 if(eve->posted)
1202
5c1a01c6384d Think we need to check the posted state inside the mutex...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1201
diff changeset
10245 {
5c1a01c6384d Think we need to check the posted state inside the mutex...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1201
diff changeset
10246 pthread_mutex_unlock (&(eve->mutex));
5c1a01c6384d Think we need to check the posted state inside the mutex...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1201
diff changeset
10247 return DW_ERROR_NONE;
5c1a01c6384d Think we need to check the posted state inside the mutex...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1201
diff changeset
10248 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10249
1155
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10250 if(timeout != -1)
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10251 {
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10252 struct timeval now;
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10253 struct timespec timeo;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10254
1155
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10255 gettimeofday(&now, 0);
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10256 timeo.tv_sec = now.tv_sec + (timeout / 1000);
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10257 timeo.tv_nsec = now.tv_usec * 1000;
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10258 rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo);
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10259 }
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10260 else
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10261 rc = pthread_cond_wait(&(eve->event), &(eve->mutex));
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10262 pthread_mutex_unlock (&(eve->mutex));
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10263 if(!rc)
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10264 return DW_ERROR_NONE;
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10265 if(rc == ETIMEDOUT)
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10266 return DW_ERROR_TIMEOUT;
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10267 return DW_ERROR_GENERAL;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10268 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10269
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10270 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10271 * Closes a semaphore created by dw_event_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10272 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10273 * eve: The handle to the event returned by dw_event_new().
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10274 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10275 int dw_event_close(HEV *eve)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10276 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10277 if(!eve || !(*eve))
986
87dc0f5f96d0 Fix return type of dw_listbox_selected() to be "int" instead of "unsigned int" to allow -1 return.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 983
diff changeset
10278 return DW_ERROR_NON_INIT;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10279
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10280 pthread_mutex_lock (&((*eve)->mutex));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10281 pthread_cond_destroy (&((*eve)->event));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10282 pthread_mutex_unlock (&((*eve)->mutex));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10283 pthread_mutex_destroy (&((*eve)->mutex));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10284 free(*eve);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10285 *eve = NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10286
986
87dc0f5f96d0 Fix return type of dw_listbox_selected() to be "int" instead of "unsigned int" to allow -1 return.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 983
diff changeset
10287 return DW_ERROR_NONE;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10288 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10289
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10290 struct _seminfo {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10291 int fd;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10292 int waiting;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10293 };
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10294
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10295 static void _handle_sem(int *tmpsock)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10296 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10297 fd_set rd;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10298 struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10299 int listenfd = tmpsock[0];
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10300 int bytesread, connectcount = 1, maxfd, z, posted = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10301 char command;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10302 sigset_t mask;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10303
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10304 sigfillset(&mask); /* Mask all allowed signals */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10305 pthread_sigmask(SIG_BLOCK, &mask, NULL);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10306
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10307 /* problems */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10308 if(tmpsock[1] == -1)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10309 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10310 free(array);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10311 return;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10312 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10313
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10314 array[0].fd = tmpsock[1];
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10315 array[0].waiting = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10316
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10317 /* Free the memory allocated in dw_named_event_new. */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10318 free(tmpsock);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10319
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10320 while(1)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10321 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10322 FD_ZERO(&rd);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10323 FD_SET(listenfd, &rd);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10324
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10325 maxfd = listenfd;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10326
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10327 /* Added any connections to the named event semaphore */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10328 for(z=0;z<connectcount;z++)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10329 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10330 if(array[z].fd > maxfd)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10331 maxfd = array[z].fd;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10332
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10333 FD_SET(array[z].fd, &rd);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10334 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10335
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10336 if(select(maxfd+1, &rd, NULL, NULL, NULL) == -1)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10337 return;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10338
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10339 if(FD_ISSET(listenfd, &rd))
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10340 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10341 struct _seminfo *newarray;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10342 int newfd = accept(listenfd, 0, 0);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10343
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10344 if(newfd > -1)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10345 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10346 /* Add new connections to the set */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10347 newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount+1));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10348 memcpy(newarray, array, sizeof(struct _seminfo)*(connectcount));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10349
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10350 newarray[connectcount].fd = newfd;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10351 newarray[connectcount].waiting = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10352
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10353 connectcount++;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10354
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10355 /* Replace old array with new one */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10356 free(array);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10357 array = newarray;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10358 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10359 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10360
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10361 /* Handle any events posted to the semaphore */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10362 for(z=0;z<connectcount;z++)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10363 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10364 if(FD_ISSET(array[z].fd, &rd))
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10365 {
1110
404b639f096b Minor typecast fixes for warnings reported by clang on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1102
diff changeset
10366 if((bytesread = (int)read(array[z].fd, &command, 1)) < 1)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10367 {
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10368 struct _seminfo *newarray = NULL;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10369
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10370 /* Remove this connection from the set */
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10371 if(connectcount > 1)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10372 {
1764
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10373 newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount-1));
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10374 if(!z)
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10375 memcpy(newarray, &array[1], sizeof(struct _seminfo)*(connectcount-1));
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10376 else
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10377 {
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10378 memcpy(newarray, array, sizeof(struct _seminfo)*z);
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10379 if(z!=(connectcount-1))
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10380 memcpy(&newarray[z], &array[z+1], sizeof(struct _seminfo)*(z-connectcount-1));
5ffeea4a2a4b Fixed a memory leak in the Mac box code, items were not being freed when destroyed.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1748
diff changeset
10381 }
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10382 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10383 connectcount--;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10384
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10385 /* Replace old array with new one */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10386 free(array);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10387 array = newarray;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10388 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10389 else if(bytesread == 1)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10390 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10391 switch(command)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10392 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10393 case 0:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10394 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10395 /* Reset */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10396 posted = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10397 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10398 break;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10399 case 1:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10400 /* Post */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10401 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10402 int s;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10403 char tmp = (char)0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10404
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10405 posted = 1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10406
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10407 for(s=0;s<connectcount;s++)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10408 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10409 /* The semaphore has been posted so
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10410 * we tell all the waiting threads to
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10411 * continue.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10412 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10413 if(array[s].waiting)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10414 write(array[s].fd, &tmp, 1);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10415 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10416 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10417 break;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10418 case 2:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10419 /* Wait */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10420 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10421 char tmp = (char)0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10422
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10423 array[z].waiting = 1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10424
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10425 /* If we are posted exit immeditately */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10426 if(posted)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10427 write(array[z].fd, &tmp, 1);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10428 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10429 break;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10430 case 3:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10431 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10432 /* Done Waiting */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10433 array[z].waiting = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10434 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10435 break;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10436 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10437 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10438 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10439 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10440 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10441 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10442
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10443 /* Using domain sockets on unix for IPC */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10444 /* Create a named event semaphore which can be
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10445 * opened from other processes.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10446 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10447 * eve: Pointer to an event handle to receive handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10448 * name: Name given to semaphore which can be opened
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10449 * by other processes.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10450 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10451 HEV dw_named_event_new(char *name)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10452 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10453 struct sockaddr_un un;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10454 int ev, *tmpsock = (int *)malloc(sizeof(int)*2);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10455 HEV eve;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10456 DWTID dwthread;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10457
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10458 if(!tmpsock)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10459 return NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10460
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10461 eve = (HEV)malloc(sizeof(struct _dw_unix_event));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10462
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10463 if(!eve)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10464 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10465 free(tmpsock);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10466 return NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10467 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
10468
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10469 tmpsock[0] = socket(AF_UNIX, SOCK_STREAM, 0);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10470 ev = socket(AF_UNIX, SOCK_STREAM, 0);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10471 memset(&un, 0, sizeof(un));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10472 un.sun_family=AF_UNIX;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10473 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10474 strcpy(un.sun_path, "/tmp/.dw/");
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10475 strcat(un.sun_path, name);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10476
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10477 /* just to be safe, this should be changed
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10478 * to support multiple instances.
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10479 */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10480 remove(un.sun_path);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10481
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10482 bind(tmpsock[0], (struct sockaddr *)&un, sizeof(un));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10483 listen(tmpsock[0], 0);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10484 connect(ev, (struct sockaddr *)&un, sizeof(un));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10485 tmpsock[1] = accept(tmpsock[0], 0, 0);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10486
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10487 if(tmpsock[0] < 0 || tmpsock[1] < 0 || ev < 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10488 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10489 if(tmpsock[0] > -1)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10490 close(tmpsock[0]);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10491 if(tmpsock[1] > -1)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10492 close(tmpsock[1]);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10493 if(ev > -1)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10494 close(ev);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10495 free(tmpsock);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10496 free(eve);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10497 return NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10498 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10499
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10500 /* Create a thread to handle this event semaphore */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10501 pthread_create(&dwthread, NULL, (void *)_handle_sem, (void *)tmpsock);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10502 eve->alive = ev;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10503 return eve;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10504 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10505
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10506 /* Open an already existing named event semaphore.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10507 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10508 * eve: Pointer to an event handle to receive handle.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10509 * name: Name given to semaphore which can be opened
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10510 * by other processes.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10511 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10512 HEV dw_named_event_get(char *name)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10513 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10514 struct sockaddr_un un;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10515 HEV eve;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10516 int ev = socket(AF_UNIX, SOCK_STREAM, 0);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10517 if(ev < 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10518 return NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10519
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10520 eve = (HEV)malloc(sizeof(struct _dw_unix_event));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10521
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10522 if(!eve)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10523 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10524 close(ev);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10525 return NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10526 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10527
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10528 un.sun_family=AF_UNIX;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10529 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10530 strcpy(un.sun_path, "/tmp/.dw/");
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10531 strcat(un.sun_path, name);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10532 connect(ev, (struct sockaddr *)&un, sizeof(un));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10533 eve->alive = ev;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10534 return eve;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10535 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10536
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10537 /* Resets the event semaphore so threads who call wait
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10538 * on this semaphore will block.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10539 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10540 * eve: Handle to the semaphore obtained by
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10541 * an open or create call.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10542 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10543 int dw_named_event_reset(HEV eve)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10544 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10545 /* signal reset */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10546 char tmp = (char)0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10547
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10548 if(!eve || eve->alive < 0)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10549 return 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10550
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10551 if(write(eve->alive, &tmp, 1) == 1)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10552 return 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10553 return 1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10554 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10555
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10556 /* Sets the posted state of an event semaphore, any threads
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10557 * waiting on the semaphore will no longer block.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10558 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10559 * eve: Handle to the semaphore obtained by
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10560 * an open or create call.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10561 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10562 int dw_named_event_post(HEV eve)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10563 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10564
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10565 /* signal post */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10566 char tmp = (char)1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10567
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10568 if(!eve || eve->alive < 0)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10569 return 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10570
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10571 if(write(eve->alive, &tmp, 1) == 1)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10572 return 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10573 return 1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10574 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10575
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10576 /* Waits on the specified semaphore until it becomes
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10577 * posted, or returns immediately if it already is posted.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10578 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10579 * eve: Handle to the semaphore obtained by
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10580 * an open or create call.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10581 * timeout: Number of milliseconds before timing out
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10582 * or -1 if indefinite.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10583 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10584 int dw_named_event_wait(HEV eve, unsigned long timeout)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10585 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10586 fd_set rd;
1155
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10587 struct timeval tv, *useme = NULL;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10588 int retval = 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10589 char tmp;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10590
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10591 if(!eve || eve->alive < 0)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10592 return DW_ERROR_NON_INIT;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10593
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10594 /* Set the timout or infinite */
1155
e6a2f57c0842 Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1152
diff changeset
10595 if(timeout != -1)
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10596 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10597 tv.tv_sec = timeout / 1000;
1110
404b639f096b Minor typecast fixes for warnings reported by clang on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1102
diff changeset
10598 tv.tv_usec = (int)timeout % 1000;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10599
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10600 useme = &tv;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10601 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10602
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10603 FD_ZERO(&rd);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10604 FD_SET(eve->alive, &rd);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10605
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10606 /* Signal wait */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10607 tmp = (char)2;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10608 write(eve->alive, &tmp, 1);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10609
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10610 retval = select(eve->alive+1, &rd, NULL, NULL, useme);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10611
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10612 /* Signal done waiting. */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10613 tmp = (char)3;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10614 write(eve->alive, &tmp, 1);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10615
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10616 if(retval == 0)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10617 return DW_ERROR_TIMEOUT;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10618 else if(retval == -1)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10619 return DW_ERROR_INTERRUPT;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10620
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10621 /* Clear the entry from the pipe so
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10622 * we don't loop endlessly. :)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10623 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10624 read(eve->alive, &tmp, 1);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10625 return 0;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10626 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10627
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10628 /* Release this semaphore, if there are no more open
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10629 * handles on this semaphore the semaphore will be destroyed.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10630 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10631 * eve: Handle to the semaphore obtained by
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10632 * an open or create call.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10633 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10634 int dw_named_event_close(HEV eve)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10635 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10636 /* Finally close the domain socket,
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10637 * cleanup will continue in _handle_sem.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10638 */
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10639 if(eve)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10640 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10641 close(eve->alive);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10642 free(eve);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10643 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10644 return 0;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10645 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10646
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10647 /* Mac specific function to cause garbage collection */
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10648 void _dw_pool_drain(void)
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10649 {
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10650 #if !defined(GARBAGE_COLLECT)
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10651 NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key);
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10652 [pool drain];
698
e19f69a78f21 Fix for pool being removed and not just drained.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 697
diff changeset
10653 pool = [[NSAutoreleasePool alloc] init];
e19f69a78f21 Fix for pool being removed and not just drained.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 697
diff changeset
10654 pthread_setspecific(_dw_pool_key, pool);
731
6a589a1a42b0 Add dw_window_get_font()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 730
diff changeset
10655 #endif
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10656 }
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10657
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10658 /*
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10659 * Setup thread independent pools.
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10660 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10661 void _dwthreadstart(void *data)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10662 {
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10663 void (*threadfunc)(void *) = NULL;
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10664 void **tmp = (void **)data;
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10665 NSColor *color;
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
10666
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
10667 /* If we aren't using garbage collection we need autorelease pools */
660
2784e7ee8bcb Fixes for pixmaps and drawing to the screen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 659
diff changeset
10668 #if !defined(GARBAGE_COLLECT)
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10669 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10670 pthread_setspecific(_dw_pool_key, pool);
660
2784e7ee8bcb Fixes for pixmaps and drawing to the screen.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 659
diff changeset
10671 #endif
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10672 _init_colors();
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10673
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10674 threadfunc = (void (*)(void *))tmp[0];
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10675
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10676 /* Start our thread function */
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10677 threadfunc(tmp[1]);
938
cfcf66a90e8c Add support for different image file types in dw_*_from_file() functions.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 937
diff changeset
10678
671
c60a4f6cfae8 Implemented icon support on the Mac. In the process created a new HICN type.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 670
diff changeset
10679 /* Release the pool when we are done so we don't leak */
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10680 color = pthread_getspecific(_dw_fg_color_key);
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10681 [color release];
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10682 color = pthread_getspecific(_dw_bg_color_key);
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10683 [color release];
666
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
10684 #if !defined(GARBAGE_COLLECT)
698
e19f69a78f21 Fix for pool being removed and not just drained.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 697
diff changeset
10685 pool = pthread_getspecific(_dw_pool_key);
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10686 [pool drain];
666
e426de6e6c7c Changes to make the resize function more like on the other platforms.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 665
diff changeset
10687 #endif
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10688 free(tmp);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10689 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10690
1075
3d117071a50b Renamed Mac _dw_default_font() to dw_font_set_default() and added it on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1074
diff changeset
10691 /*
3d117071a50b Renamed Mac _dw_default_font() to dw_font_set_default() and added it on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1074
diff changeset
10692 * Sets the default font used on text based widgets.
3d117071a50b Renamed Mac _dw_default_font() to dw_font_set_default() and added it on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1074
diff changeset
10693 * Parameters:
3d117071a50b Renamed Mac _dw_default_font() to dw_font_set_default() and added it on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1074
diff changeset
10694 * fontname: Font name in Dynamic Windows format.
3d117071a50b Renamed Mac _dw_default_font() to dw_font_set_default() and added it on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1074
diff changeset
10695 */
3d117071a50b Renamed Mac _dw_default_font() to dw_font_set_default() and added it on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1074
diff changeset
10696 void API dw_font_set_default(char *fontname)
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
10697 {
1241
459426f31fb4 Slight thread safety fix on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1239
diff changeset
10698 NSFont *oldfont = DWDefaultFont;
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
10699 DWDefaultFont = _dw_font_by_name(fontname);
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
10700 [DWDefaultFont retain];
1241
459426f31fb4 Slight thread safety fix on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1239
diff changeset
10701 [oldfont release];
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
10702 }
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
10703
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10704 /*
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10705 * Initializes the Dynamic Windows engine.
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10706 * Parameters:
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10707 * newthread: True if this is the only thread.
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10708 * False if there is already a message loop running.
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10709 */
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10710 int API dw_init(int newthread, int argc, char *argv[])
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10711 {
1786
9a32d4216f24 Make sure we set the locale on Mac and it is UTF-8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1784
diff changeset
10712 char *lang = getenv("LANG");
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10713
1098
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10714 /* Correct the startup path if run from a bundle */
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10715 if(argc > 0 && argv[0])
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10716 {
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10717 char *pathcopy = strdup(argv[0]);
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10718 char *app = strstr(pathcopy, ".app/");
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
10719
1098
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10720 if(app)
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10721 {
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10722 char pathbuf[PATH_MAX+1] = { 0 };
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10723 size_t len = (size_t)(app - pathcopy);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10724
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10725 if(len > 0)
1385
fc20ad815428 Don't need to include the / after the .app on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1384
diff changeset
10726 strncpy(_dw_bundle_path, pathcopy, len + 4);
1098
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10727 *app = 0;
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
10728
1098
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10729 getcwd(pathbuf, PATH_MAX);
1128
7d7535f6bc4e Added ability to set background color of MLE; setting foreground still outstanding.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1120
diff changeset
10730
1098
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10731 /* If run from a bundle the path seems to be / */
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10732 if(strcmp(pathbuf, "/") == 0)
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10733 {
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10734 char *pos = strrchr(pathcopy, '/');
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10735
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10736 if(pos)
1098
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10737 {
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10738 strncpy(pathbuf, pathcopy, (size_t)(pos - pathcopy));
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10739 chdir(pathbuf);
1098
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10740 }
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10741 }
9e1d6fa397be Experimental change to set the current working directory to the bundle path on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1093
diff changeset
10742 }
1383
ead81c3d9e4e Thought I was fixing a memory leak but I was seeing the {} wrong.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1381
diff changeset
10743 if(pathcopy)
ead81c3d9e4e Thought I was fixing a memory leak but I was seeing the {} wrong.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1381
diff changeset
10744 free(pathcopy);
ead81c3d9e4e Thought I was fixing a memory leak but I was seeing the {} wrong.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1381
diff changeset
10745 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10746
1381
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10747 /* Just in case we can't obtain a path */
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10748 if(!_dw_bundle_path[0])
3ba4853d5b78 Initial attempt at dw_app_dir() for OS/2, Windows and Mac...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1378
diff changeset
10749 getcwd(_dw_bundle_path, PATH_MAX);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10750
751
eba6ab48c952 Runtime Snow Leopard checks where possible and visual fix for Leopard status text.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 749
diff changeset
10751 /* Get the operating system version */
1770
2396655d43f1 Fix some warnings with Mac 10.8 and Xcode 4.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1769
diff changeset
10752 NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString];
2396655d43f1 Fix some warnings with Mac 10.8 and Xcode 4.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1769
diff changeset
10753 const char *versionstr = [version UTF8String];
2396655d43f1 Fix some warnings with Mac 10.8 and Xcode 4.5.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1769
diff changeset
10754 sscanf(versionstr, "Version %d.%d.%d", &DWOSMajor, &DWOSMinor, &DWOSBuild);
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
10755 /* Set the locale... if it is UTF-8 pass it
1786
9a32d4216f24 Make sure we set the locale on Mac and it is UTF-8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1784
diff changeset
10756 * directly, otherwise specify UTF-8 explicitly.
9a32d4216f24 Make sure we set the locale on Mac and it is UTF-8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1784
diff changeset
10757 */
9a32d4216f24 Make sure we set the locale on Mac and it is UTF-8.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1784
diff changeset
10758 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8");
736
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10759 /* Create the application object */
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10760 DWApp = [NSApplication sharedApplication];
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10761 /* Create object for handling timers */
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10762 DWHandler = [[DWTimerHandler alloc] init];
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10763 /* If we aren't using garbage collection we need autorelease pools */
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10764 #if !defined(GARBAGE_COLLECT)
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10765 pthread_key_create(&_dw_pool_key, NULL);
736
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10766 pool = [[NSAutoreleasePool alloc] init];
726
ecf47778caff Possible fix for container string columns not showing correctly.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 725
diff changeset
10767 pthread_setspecific(_dw_pool_key, pool);
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10768 #endif
826
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10769 pthread_key_create(&_dw_fg_color_key, NULL);
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10770 pthread_key_create(&_dw_bg_color_key, NULL);
6bb8bff36548 Implemented thread specific colors. Allows threads to have their own colors... also reducing color object recreation.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 825
diff changeset
10771 _init_colors();
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10772 /* Create a default main menu, with just the application menu */
736
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10773 DWMainMenu = _generate_main_menu();
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10774 [DWMainMenu retain];
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10775 [DWApp setMainMenu:DWMainMenu];
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10776 DWObj = [[DWObject alloc] init];
744
9882b0dfa304 Added an internal Mac function for setting the default Dynamic Windows font.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 743
diff changeset
10777 DWDefaultFont = nil;
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10778 /* Create mutexes for thread safety */
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10779 DWRunMutex = dw_mutex_new();
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10780 DWThreadMutex = dw_mutex_new();
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10781 DWThreadMutex2 = dw_mutex_new();
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10782 /* Use NSThread to start a dummy thread to initialize the threading subsystem */
736
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10783 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil];
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10784 [thread start];
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10785 [thread release];
859
80a88c91ccf6 Implemented vertical centering on text fields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 858
diff changeset
10786 [NSTextField setCellClass:[DWTextFieldCell class]];
736
5b48519a7fb2 Added retains to the window menus so they don't get autoreleased when switching between
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 735
diff changeset
10787 return 0;
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10788 }
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10789
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10790 /*
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10791 * Allocates a shared memory region with a name.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10792 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10793 * handle: A pointer to receive a SHM identifier.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10794 * dest: A pointer to a pointer to receive the memory address.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10795 * size: Size in bytes of the shared memory region to allocate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10796 * name: A string pointer to a unique memory name.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10797 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10798 HSHM dw_named_memory_new(void **dest, int size, char *name)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10799 {
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
10800 char namebuf[1025] = {0};
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10801 struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10802
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10803 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH);
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
10804 snprintf(namebuf, 1024, "/tmp/.dw/%s", name);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10805
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10806 if((handle->fd = open(namebuf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10807 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10808 free(handle);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10809 return NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10810 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10811
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10812 ftruncate(handle->fd, size);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10813
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10814 /* attach the shared memory segment to our process's address space. */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10815 *dest = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10816
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10817 if(*dest == MAP_FAILED)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10818 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10819 close(handle->fd);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10820 *dest = NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10821 free(handle);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10822 return NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10823 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10824
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10825 handle->size = size;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10826 handle->sid = getsid(0);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10827 handle->path = strdup(namebuf);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10828
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10829 return handle;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10830 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10831
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10832 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10833 * Aquires shared memory region with a name.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10834 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10835 * dest: A pointer to a pointer to receive the memory address.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10836 * size: Size in bytes of the shared memory region to requested.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10837 * name: A string pointer to a unique memory name.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10838 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10839 HSHM dw_named_memory_get(void **dest, int size, char *name)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10840 {
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
10841 char namebuf[1025];
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10842 struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm));
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10843
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10844 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH);
1306
dbd507f42947 Added dw_debug() logging function which will output a message to the debugging console.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1303
diff changeset
10845 snprintf(namebuf, 1024, "/tmp/.dw/%s", name);
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10846
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10847 if((handle->fd = open(namebuf, O_RDWR)) < 0)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10848 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10849 free(handle);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10850 return NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10851 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10852
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10853 /* attach the shared memory segment to our process's address space. */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10854 *dest = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10855
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10856 if(*dest == MAP_FAILED)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10857 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10858 close(handle->fd);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10859 *dest = NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10860 free(handle);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10861 return NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10862 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10863
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10864 handle->size = size;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10865 handle->sid = -1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10866 handle->path = NULL;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10867
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10868 return handle;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10869 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10870
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10871 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10872 * Frees a shared memory region previously allocated.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10873 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10874 * handle: Handle obtained from DB_named_memory_allocate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10875 * ptr: The memory address aquired with DB_named_memory_allocate.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10876 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10877 int dw_named_memory_free(HSHM handle, void *ptr)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10878 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10879 struct _dw_unix_shm *h = handle;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10880 int rc = munmap(ptr, h->size);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10881
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10882 close(h->fd);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10883 if(h->path)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10884 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10885 /* Only remove the actual file if we are the
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10886 * creator of the file.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10887 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10888 if(h->sid != -1 && h->sid == getsid(0))
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10889 remove(h->path);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10890 free(h->path);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10891 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10892 return rc;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10893 }
697
830e1f3672b9 Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 696
diff changeset
10894
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10895 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10896 * Creates a new thread with a starting point of func.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10897 * Parameters:
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10898 * func: Function which will be run in the new thread.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10899 * data: Parameter(s) passed to the function.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10900 * stack: Stack size of new thread (OS/2 and Windows only).
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10901 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10902 DWTID dw_thread_new(void *func, void *data, int stack)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10903 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10904 DWTID thread;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10905 void **tmp = malloc(sizeof(void *) * 2);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10906 int rc;
650
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10907
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10908 tmp[0] = func;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10909 tmp[1] = data;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10910
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10911 rc = pthread_create(&thread, NULL, (void *)_dwthreadstart, (void *)tmp);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10912 if(rc == 0)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10913 return thread;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10914 return (DWTID)-1;
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10915 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10916
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10917 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10918 * Ends execution of current thread immediately.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10919 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10920 void dw_thread_end(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10921 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10922 pthread_exit(NULL);
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10923 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10924
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10925 /*
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10926 * Returns the current thread's ID.
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10927 */
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10928 DWTID dw_thread_id(void)
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10929 {
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10930 return (DWTID)pthread_self();
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10931 }
55b677d460e9 Added initial support for a MacOS Cocoa port.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10932
661
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10933 /*
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10934 * Execute and external program in a seperate session.
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10935 * Parameters:
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10936 * program: Program name with optional path.
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10937 * type: Either DW_EXEC_CON or DW_EXEC_GUI.
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10938 * params: An array of pointers to string arguements.
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10939 * Returns:
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10940 * -1 on error.
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10941 */
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10942 int dw_exec(char *program, int type, char **params)
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
10943 {
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10944 int ret = -1;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
10945
738
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10946 if(type == DW_EXEC_GUI)
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10947 {
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10948 if(params && params[0] && params[1])
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10949 {
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10950 [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithUTF8String:params[1]]
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10951 withApplication:[NSString stringWithUTF8String:program]];
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10952 }
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10953 else
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10954 {
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10955 [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:program]];
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10956 }
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10957 return 0;
52d5ed00f892 Use NSWorkplace to launch GUI applications instead of fork() and exec().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 737
diff changeset
10958 }
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
10959
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10960 if((ret = fork()) == 0)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10961 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10962 int i;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
10963
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10964 for (i = 3; i < 256; i++)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10965 close(i);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10966 setsid();
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
10967
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10968 if(type == DW_EXEC_CON)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10969 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10970 char **tmpargs;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
10971
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10972 if(!params)
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10973 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10974 tmpargs = malloc(sizeof(char *));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10975 tmpargs[0] = NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10976 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10977 else
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10978 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10979 int z = 0;
762
2aaa3f67cfb1 Fix for crashes with generating images from data
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 760
diff changeset
10980
752
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10981 while(params[z])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10982 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10983 z++;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10984 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10985 tmpargs = malloc(sizeof(char *)*(z+3));
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10986 z=0;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10987 tmpargs[0] = "xterm";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10988 tmpargs[1] = "-e";
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10989 while(params[z])
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10990 {
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10991 tmpargs[z+2] = params[z];
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10992 z++;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10993 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10994 tmpargs[z+2] = NULL;
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10995 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10996 execvp("xterm", tmpargs);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10997 free(tmpargs);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10998 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
10999 /* If we got here exec failed */
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
11000 _exit(-1);
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
11001 }
cf447811d322 Converted tabs to spaces.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 751
diff changeset
11002 return ret;
661
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11003 }
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11004
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11005 /*
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11006 * Loads a web browser pointed at the given URL.
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11007 * Parameters:
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11008 * url: Uniform resource locator.
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11009 */
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11010 int dw_browse(char *url)
eee90a788876 Added missing functions needed to build HandyFTP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 660
diff changeset
11011 {
715
5f8102bd7646 dw_browse() reimplmented so it actually works as expected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 714
diff changeset
11012 NSURL *myurl = [NSURL URLWithString:[NSString stringWithUTF8String:url]];
5f8102bd7646 dw_browse() reimplmented so it actually works as expected.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 714
diff changeset
11013 [[NSWorkspace sharedWorkspace] openURL:myurl];
1115
03cd2f3e929d Fixed a documentation and template error regarding dw_browse() return code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1110
diff changeset
11014 return DW_ERROR_NONE;
03cd2f3e929d Fixed a documentation and template error regarding dw_browse() return code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1110
diff changeset
11015 }
1137
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11016
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11017 typedef struct _dwprint
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11018 {
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11019 NSPrintInfo *pi;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11020 int (*drawfunc)(HPRINT, HPIXMAP, int, void *);
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11021 void *drawdata;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11022 unsigned long flags;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11023 } DWPrint;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11024
1137
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11025 /*
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11026 * Creates a new print object.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11027 * Parameters:
1152
58b5374355ab Added print jobname parameter to dw_print_new().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1147
diff changeset
11028 * jobname: Name of the print job to show in the queue.
1137
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11029 * flags: Flags to initially configure the print object.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11030 * pages: Number of pages to print.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11031 * drawfunc: The pointer to the function to be used as the callback.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11032 * drawdata: User data to be passed to the handler function.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11033 * Returns:
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11034 * A handle to the print object or NULL on failure.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11035 */
1152
58b5374355ab Added print jobname parameter to dw_print_new().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1147
diff changeset
11036 HPRINT API dw_print_new(char *jobname, unsigned long flags, unsigned int pages, void *drawfunc, void *drawdata)
1137
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11037 {
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11038 DWPrint *print;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11039 NSPrintPanel *panel;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11040 PMPrintSettings settings;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11041 NSPrintInfo *pi;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11042
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11043 if(!drawfunc || !(print = calloc(1, sizeof(DWPrint))))
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11044 {
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11045 return NULL;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11046 }
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11047
1152
58b5374355ab Added print jobname parameter to dw_print_new().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1147
diff changeset
11048 if(!jobname)
58b5374355ab Added print jobname parameter to dw_print_new().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1147
diff changeset
11049 jobname = "Dynamic Windows Print Job";
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11050
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11051 print->drawfunc = drawfunc;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11052 print->drawdata = drawdata;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11053 print->flags = flags;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11054
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11055 /* Get the page range */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11056 pi = [NSPrintInfo sharedPrintInfo];
1237
f8673299ec37 Ok if we setup the print information on Mac we get a better size...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1236
diff changeset
11057 [pi setHorizontalPagination:NSFitPagination];
f8673299ec37 Ok if we setup the print information on Mac we get a better size...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1236
diff changeset
11058 [pi setHorizontallyCentered:YES];
f8673299ec37 Ok if we setup the print information on Mac we get a better size...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1236
diff changeset
11059 [pi setVerticalPagination:NSFitPagination];
f8673299ec37 Ok if we setup the print information on Mac we get a better size...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1236
diff changeset
11060 [pi setVerticallyCentered:YES];
1239
7ec60b650e5b Printer info should default to Portrait not Landscape on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1237
diff changeset
11061 [pi setOrientation:NSPortraitOrientation];
1237
f8673299ec37 Ok if we setup the print information on Mac we get a better size...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1236
diff changeset
11062 [pi setLeftMargin:0.0];
f8673299ec37 Ok if we setup the print information on Mac we get a better size...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1236
diff changeset
11063 [pi setRightMargin:0.0];
f8673299ec37 Ok if we setup the print information on Mac we get a better size...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1236
diff changeset
11064 [pi setTopMargin:0.0];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11065 [pi setBottomMargin:0.0];
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11066
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11067 settings = [pi PMPrintSettings];
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11068 PMSetPageRange(settings, 1, pages);
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11069 PMSetFirstPage(settings, 1, true);
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11070 PMSetLastPage(settings, pages, true);
1152
58b5374355ab Added print jobname parameter to dw_print_new().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1147
diff changeset
11071 PMPrintSettingsSetJobName(settings, (CFStringRef)[NSString stringWithUTF8String:jobname]);
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11072 [pi updateFromPMPrintSettings];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11073
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11074 /* Create and show the print panel */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11075 panel = [NSPrintPanel printPanel];
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11076 if(!panel || [panel runModalWithPrintInfo:pi] == NSCancelButton)
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11077 {
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11078 free(print);
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11079 return NULL;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11080 }
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11081 /* Put the print info from the panel into the operation */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11082 print->pi = pi;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11083
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11084 return print;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11085 }
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11086
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11087 /*
1137
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11088 * Runs the print job, causing the draw page callbacks to fire.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11089 * Parameters:
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11090 * print: Handle to the print object returned by dw_print_new().
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11091 * flags: Flags to run the print job.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11092 * Returns:
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11093 * DW_ERROR_UNKNOWN on error or DW_ERROR_NONE on success.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11094 */
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11095 int API dw_print_run(HPRINT print, unsigned long flags)
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11096 {
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11097 DWPrint *p = print;
1175
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11098 NSBitmapImageRep *rep, *rep2;
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11099 NSPrintInfo *pi;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11100 NSPrintOperation *po;
1175
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11101 HPIXMAP pixmap, pixmap2;
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11102 NSImage *image, *flipped;
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11103 NSImageView *iv;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11104 NSSize size;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11105 PMPrintSettings settings;
1143
b1b23de965d7 Fixed using a pointer after being free()ed on Windows and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1141
diff changeset
11106 int x, result = DW_ERROR_UNKNOWN;
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11107 UInt32 start, end;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11108
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11109 if(!p)
1143
b1b23de965d7 Fixed using a pointer after being free()ed on Windows and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1141
diff changeset
11110 return result;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11111
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
11112 DW_LOCAL_POOL_IN;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11113
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11114 /* Figure out the printer/paper size */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11115 pi = p->pi;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11116 size = [pi paperSize];
1234
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11117
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11118 /* Get the page range */
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11119 settings = [pi PMPrintSettings];
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11120 PMGetFirstPage(settings, &start);
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11121 if(start > 0)
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11122 start--;
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11123 PMGetLastPage(settings, &end);
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11124 PMSetPageRange(settings, 1, 1);
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11125 PMSetFirstPage(settings, 1, true);
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11126 PMSetLastPage(settings, 1, true);
bee6fc8119ec Paper size reported on Mac height is for all pages...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1230
diff changeset
11127 [pi updateFromPMPrintSettings];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11128
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11129 /* Create an image view to print and a pixmap to draw into */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11130 iv = [[NSImageView alloc] init];
1143
b1b23de965d7 Fixed using a pointer after being free()ed on Windows and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1141
diff changeset
11131 pixmap = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8);
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11132 rep = pixmap->image;
1175
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11133 pixmap2 = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8);
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11134 rep2 = pixmap2->image;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11135
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11136 /* Create an image with the data from the pixmap
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11137 * to go into the image view.
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11138 */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11139 image = [[NSImage alloc] initWithSize:[rep size]];
1175
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11140 flipped = [[NSImage alloc] initWithSize:[rep size]];
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11141 [image addRepresentation:rep];
1176
408ea33b19cf Ok fixed a problem with the last commit using the wrong representation on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1175
diff changeset
11142 [flipped addRepresentation:rep2];
1175
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11143 [iv setImage:flipped];
1144
5878dbfafbe2 Need to size the NSImageView to print it apparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1143
diff changeset
11144 [iv setImageScaling:NSScaleProportionally];
5878dbfafbe2 Need to size the NSImageView to print it apparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1143
diff changeset
11145 [iv setFrameOrigin:NSMakePoint(0,0)];
5878dbfafbe2 Need to size the NSImageView to print it apparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1143
diff changeset
11146 [iv setFrameSize:size];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11147
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11148 /* Create the print operation using the image view and
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11149 * print info obtained from the panel in the last call.
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11150 */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11151 po = [NSPrintOperation printOperationWithView:iv printInfo:pi];
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11152 [po setShowsPrintPanel:NO];
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11153
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11154 /* Cycle through each page */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11155 for(x=start; x<end && p->drawfunc; x++)
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11156 {
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11157 /* Call the application's draw function */
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11158 p->drawfunc(print, pixmap, x, p->drawdata);
1340
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11159 if(p->drawfunc)
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11160 {
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11161 /* Internal representation is flipped... so flip again so we can print */
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11162 _flip_image(image, rep2, size);
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11163 #ifdef DEBUG_PRINT
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11164 /* Save it to file to see what we have */
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11165 NSData *data = [rep2 representationUsingType: NSPNGFileType properties: nil];
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11166 [data writeToFile: @"print.png" atomically: NO];
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11167 #endif
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11168 /* Print the image view */
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11169 [po runOperation];
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11170 /* Fill the pixmap with white in case we are printing more pages */
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11171 dw_color_foreground_set(DW_CLR_WHITE);
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11172 dw_draw_rect(0, pixmap, TRUE, 0, 0, (int)size.width, (int)size.height);
890890c31ba6 Another printing cancel fix for the Mac and updated the readme.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1335
diff changeset
11173 }
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11174 }
1143
b1b23de965d7 Fixed using a pointer after being free()ed on Windows and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1141
diff changeset
11175 if(p->drawfunc)
b1b23de965d7 Fixed using a pointer after being free()ed on Windows and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1141
diff changeset
11176 result = DW_ERROR_NONE;
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11177 /* Free memory */
1144
5878dbfafbe2 Need to size the NSImageView to print it apparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1143
diff changeset
11178 [image release];
1175
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11179 [flipped release];
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11180 dw_pixmap_destroy(pixmap);
1175
eb4589ddff3e Added some test code to save what we are trying to print as a PNG on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1160
diff changeset
11181 dw_pixmap_destroy(pixmap2);
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11182 free(p);
1144
5878dbfafbe2 Need to size the NSImageView to print it apparently on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1143
diff changeset
11183 [iv release];
1582
728778634933 Performed a more thorough audit of functions on Mac that require local pools.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1580
diff changeset
11184 DW_LOCAL_POOL_OUT;
1143
b1b23de965d7 Fixed using a pointer after being free()ed on Windows and Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1141
diff changeset
11185 return result;
1137
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11186 }
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11187
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11188 /*
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11189 * Cancels the print job, typically called from a draw page callback.
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11190 * Parameters:
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11191 * print: Handle to the print object returned by dw_print_new().
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11192 */
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11193 void API dw_print_cancel(HPRINT print)
e24e5a13ff2c Added code to test the new print functions in dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1135
diff changeset
11194 {
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11195 DWPrint *p = print;
1802
aedf5903db0a Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1795
diff changeset
11196
1141
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11197 if(p)
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11198 p->drawfunc = NULL;
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11199 }
8d8c73fb27f4 Initial implementation of printing support on Mac.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1137
diff changeset
11200
1783
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11201 /*
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11202 * Converts a UTF-8 encoded string into a wide string.
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11203 * Parameters:
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11204 * utf8string: UTF-8 encoded source string.
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11205 * Returns:
1784
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11206 * Wide string that needs to be freed with dw_free()
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11207 * or NULL on failure.
1783
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11208 */
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11209 wchar_t * API dw_utf8_to_wchar(char *utf8string)
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11210 {
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11211 size_t buflen = strlen(utf8string) + 1;
1784
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11212 wchar_t *temp = malloc(buflen * sizeof(wchar_t));
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11213 if(temp)
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11214 mbstowcs(temp, utf8string, buflen);
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11215 return temp;
1783
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11216 }
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11217
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11218 /*
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11219 * Converts a wide string into a UTF-8 encoded string.
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11220 * Parameters:
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11221 * wstring: Wide source string.
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11222 * Returns:
1784
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11223 * UTF-8 encoded string that needs to be freed with dw_free()
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11224 * or NULL on failure.
1783
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11225 */
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11226 char * API dw_wchar_to_utf8(wchar_t *wstring)
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11227 {
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11228 size_t bufflen = 8 * wcslen(wstring) + 1;
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11229 char *temp = malloc(bufflen);
1784
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11230 if(temp)
86ace55df07b Added UTF8/Wide conversion functions on OS/2 and Windows...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1783
diff changeset
11231 wcstombs(temp, wstring, bufflen);
1783
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11232 return temp;
9de6d1cc8fb8 Put test program code into DEPRECATED #ifdef again to avoid build warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1782
diff changeset
11233 }