~ubuntu-branches/ubuntu/trusty/argyll/trusty-proposed

« back to all changes in this revision

Viewing changes to plot/osx/helloc.c

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-02-12 00:35:39 UTC
  • mfrom: (13.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20140212003539-24tautzlitsiz61w
Tags: 1.5.1-5ubuntu1
* Merge from Debian unstable. (LP: #1275572) Remaining changes:
  - debian/control:
    + Build-depend on libtiff-dev rather than libtiff4-dev.
  - debian/control, debian/patches/06_fix_udev_rule.patch:
    + Fix udev rules to actually work; ENV{ACL_MANAGE} has
      stopped working ages ago, and with logind it's now the
      "uaccess" tag. Dropping also consolekit from Recommends.
  - debian/patches/drop-usb-db.patch:
    + Use hwdb builtin, instead of the obsolete usb-db
      in the udev rules.
* debian/patches/05_ftbfs-underlinkage.diff:
  - Dropped change, no needed anymore.
* Refresh the patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <stdio.h>
 
3
#include <stdlib.h>
 
4
#include <string.h>
 
5
 
 
6
#ifdef __OBJC__
 
7
# include <Foundation/Foundation.h>
 
8
# include <AppKit/AppKit.h>
 
9
#endif
 
10
 
 
11
#include "acocoa.h"             /* Argyll Cocoa support functions and defines */
 
12
 
 
13
/*
 
14
- (void) someMethod:...
 
15
{
 
16
    va_list va;
 
17
 
 
18
    va_start(va, _cmd);
 
19
 
 
20
    // process all args with va_arg
 
21
 
 
22
    va_end(va);
 
23
}
 
24
 */
 
25
 
 
26
/* Our static instance variables for AppDelegate */
 
27
typedef struct {
 
28
    id window;          /* NSWindow */
 
29
    id view;            /* NSView */
 
30
} cntx_t;
 
31
 
 
32
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
33
 
 
34
void MyView_setCntx(id self, SEL _cmd, void *val) {
 
35
        object_setInstanceVariable(self, "cntx", val);
 
36
}
 
37
 
 
38
void MyView_drawRect(id self, SEL _cmd, NSRect rect) {
 
39
        double w = rect.size.width, h = rect.size.height;
 
40
 
 
41
        id aPath = sendClassMsg("NSBezierPath", "bezierPath");
 
42
        sendMsg(aPath, "setLineWidth:", 2.0);
 
43
        sendMsg(aPath, "moveToPoint:", NSMakePoint(0.0, 0.0));
 
44
        sendMsg(aPath, "lineToPoint:", NSMakePoint(0.9 * w, 0.9 * h));
 
45
        sendMsg(aPath, "appendBezierPathWithRect:", NSMakeRect(0.5 * w, 0.5 * h,
 
46
                                                                   0.7 * w, 0.6 * h));
 
47
        sendMsg(aPath, "stroke");
 
48
 
 
49
        {
 
50
                id att = newObject("NSDictionary");
 
51
                id str = newNSString("String");
 
52
                sendMsg(str, "drawAtPoint:withAttributes:", NSMakePoint(0.1 * w, 0.1 * h), att); 
 
53
        }
 
54
}
 
55
 
 
56
/* Clean up */
 
57
void MyView_dealloc(id self, SEL _cmd) {
 
58
        delObjectSuper(self);
 
59
}
 
60
 
 
61
// Create our custom NSView */
 
62
void createMyView() {
 
63
        method_info minfo[] = {
 
64
                { "setCntx:",          (IMP)MyView_setCntx,          "v@:^v" },
 
65
                { "drawRect:",         (IMP)MyView_drawRect,         "v@:@"  },
 
66
                { "dealloc",           (IMP)MyView_dealloc,          "v@:"   },
 
67
                { "" }
 
68
        };
 
69
 
 
70
        variable_info vinfo[] = {
 
71
                { "cntx", sizeof(void *), "^v" },
 
72
                { "" }
 
73
        };
 
74
 
 
75
        registerClass("MyView", "NSView", minfo, vinfo);
 
76
}
 
77
 
 
78
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
79
 
 
80
void MyWin_setCntx(id self, SEL _cmd, void *val) {
 
81
        object_setInstanceVariable(self, "cntx", val);
 
82
}
 
83
 
 
84
void MyWin_keyDown(id self, SEL _cmd, id event) {
 
85
        int etype;
 
86
        id nresp;
 
87
        id str;
 
88
        const char *cstr;
 
89
 
 
90
        etype = (int)sendMsg(event, "type");
 
91
        str = sendMsg(event, "characters");
 
92
        cstr = cNSString(str); 
 
93
        printf("Got Window KeyDown type %d, chars '%s'\n",etype, cstr);
 
94
 
 
95
        if (cstr[0] == ' ')
 
96
                sendMsg(NSApp, "terminate:", self);
 
97
}
 
98
 
 
99
/* Clean up */
 
100
void MyWin_dealloc(id self, SEL _cmd) {
 
101
        delObjectSuper(self);
 
102
}
 
103
 
 
104
// Create our custom NSWin */
 
105
void createMyWin() {
 
106
        method_info minfo[] = {
 
107
                { "setCntx:",             (IMP)MyWin_setCntx,              "v@:^v", },
 
108
                { "keyDown:",             (IMP)MyWin_keyDown,              "v@:@",  },
 
109
                { "dealloc",              (IMP)MyWin_dealloc,              "v@:"    },
 
110
                { "" }
 
111
        };
 
112
 
 
113
        variable_info vinfo[] = {
 
114
                { "cntx", sizeof(void *), "^v" },
 
115
                { "" }
 
116
        };
 
117
 
 
118
        registerClass("MyWin", "NSWindow", minfo, vinfo);
 
119
}
 
120
 
 
121
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
122
 
 
123
/* Create all the bits */
 
124
void AppDel_willFinishLaunching(id self, SEL _cmd, id notification) {
 
125
        cntx_t *cx;
 
126
        id label;               /* NSTextField */
 
127
 
 
128
        cx = calloc(1, sizeof(cntx_t));
 
129
 
 
130
        // Set cntx to to allocated structure
 
131
        object_setInstanceVariable(self, "cntx", (void *)cx);
 
132
 
 
133
        /* Create Window */
 
134
    cx->window = sendClassMsg("MyWin", "alloc");
 
135
    cx->window = sendMsg(cx->window,
 
136
                                     "initWithContentRect:styleMask:backing:defer:",
 
137
                                     NSMakeRect(300, 300, 200, 100),
 
138
                                 NSTitledWindowMask
 
139
                                   | NSClosableWindowMask
 
140
                                   | NSMiniaturizableWindowMask
 
141
                                   | NSResizableWindowMask,
 
142
                                 NSBackingStoreBuffered,
 
143
                                     YES);
 
144
 
 
145
        /* Make the background white */
 
146
        sendMsg(cx->window, "setBackgroundColor:", sendClassMsg("NSColor","whiteColor"));
 
147
 
 
148
        /* Add title */
 
149
        sendMsg(cx->window, "setTitle:", newNSString("Hello World"));
 
150
        
 
151
#ifdef NEVER
 
152
        /* Create Label */
 
153
    label = sendClassMsg("NSTextField", "alloc");
 
154
    label = sendMsg(label, "initWithFrame:", NSMakeRect(30, 30, 80, 30));
 
155
 
 
156
    sendMsg(label, "setSelectable:", NO);
 
157
    sendMsg(label, "setBezeled:", NO);
 
158
    sendMsg(label, "setDrawsBackground:", NO);
 
159
    sendMsg(label, "setStringValue:", newNSString("Hello World"));
 
160
 
 
161
        /* Hmm. How does this work ? */
 
162
    cx->view = sendMsg(cx->window, "contentView");
 
163
    sendMsg(cx->view, "addSubview:", label);
 
164
#else
 
165
        /* Use our custom view to draw contents */
 
166
    cx->view = newObject("MyView");
 
167
 
 
168
    sendMsg(cx->view, "setCntx:", (void *)cx);
 
169
    sendMsg(cx->window, "setContentView:", cx->view);
 
170
 
 
171
//      sendMsg(cx->window, "setInitialFirstResponder:", cx->view);
 
172
#endif
 
173
 
 
174
        // Window methods:
 
175
 
 
176
        // sendEvent: gets messages.
 
177
 
 
178
        // Set above the screen saver
 
179
        // [aWindow setLevel:NSScreenSaverWindowLevel + 1];
 
180
 
 
181
        // setCollectionBehavior: NSWindowCollectionBehaviorIgnoresCycle
 
182
        //                        NSWindowCollectionBehaviorFullScreenPrimary
 
183
        //                        NSWindowCollectionBehaviorStationary                          
 
184
        //                        NSWindowCollectionBehaviorIgnoresCycle                                
 
185
 
 
186
        // center
 
187
        // mouseDownCanMoveWindow 
 
188
        // setMovable: 
 
189
        // setContentMinSize: and setContentMaxSize:
 
190
        //
 
191
    // NSRect frame = [myWindow frame];
 
192
    // if (frame.size.width <= MIN_WIDTH_WITH_ADDITIONS)
 
193
    //     frame.size.width = MIN_WIDTH_WITH_ADDITIONS;
 
194
    // frame.size.height += ADDITIONS_HEIGHT;
 
195
    // frame.origin.y -= ADDITIONS_HEIGHT;
 
196
    // [myWindow setFrame:frame display:YES animate:YES];
 
197
    // objc_msgSend(label, "release"));
 
198
        //
 
199
        // setExcludedFromWindowsMenu:YES
 
200
        //
 
201
        // setBackgroundColor: and setAlphaValue:
 
202
 
 
203
        // WindowImage object:
 
204
        // setDepthLimit:
 
205
 
 
206
        // Setting cursor:
 
207
        // NSTrackingArea class, along with the cursorUpdate: method of the NSResponder class
 
208
        
 
209
}
 
210
 
 
211
/* Map the window */
 
212
void AppDel_didFinishLaunching(id self, SEL _cmd, id notification) {
 
213
    cntx_t *cx;
 
214
 
 
215
        object_getInstanceVariable(self, "cntx", (void **)&cx);
 
216
    sendMsg(cx->window, "makeKeyAndOrderFront:", self);
 
217
 
 
218
#ifdef NEVER            /* Test terminate */
 
219
        sleep(5);
 
220
        sendMsg(NSApp, "terminate:", self);
 
221
#endif
 
222
}
 
223
 
 
224
/* Should the application terminate ? */
 
225
NSApplicationTerminateReply AppDel_shouldTerminate(id self, SEL _cmd, id notification) {
 
226
        return NSTerminateNow;
 
227
}
 
228
 
 
229
/* Clean up */
 
230
void AppDel_dealloc(id self, SEL _cmd) {
 
231
    cntx_t *cx;
 
232
 
 
233
        object_getInstanceVariable(self, "cntx", (void **)&cx);
 
234
    delObject(cx->window);
 
235
        delObjectSuper(self);
 
236
}
 
237
 
 
238
// Create the delegate class that implements our window
 
239
void createAppDelClass() {
 
240
        method_info minfo[] = {
 
241
                { "applicationWillFinishLaunching:", (IMP)AppDel_willFinishLaunching, "v@:@" },
 
242
                { "applicationDidFinishLaunching:",  (IMP)AppDel_didFinishLaunching,  "v@:@" },
 
243
                { "applicationShouldTerminate:",     (IMP)AppDel_shouldTerminate,     "i@:@" },
 
244
                { "dealloc",                         (IMP)AppDel_dealloc,             "v@:"  },
 
245
                { "" }
 
246
        };
 
247
 
 
248
        variable_info vinfo[] = {
 
249
                { "cntx", sizeof(void *), "^v" },
 
250
                { "" }
 
251
        };
 
252
 
 
253
        registerClass("AppDelegate", "NSObject", minfo, vinfo);
 
254
}
 
255
 
 
256
/* - - - - - - - - - - - - - - - - - - - - - - - - */
 
257
int main(int argc, char** argv) {
 
258
        id pool;
 
259
        id appDelObj;
 
260
 
 
261
        /* Transform process so that it interacts with desktop properly */
 
262
        transProcess();
 
263
 
 
264
        /* Create an autorelease pool */
 
265
        pool = newObject("NSAutoreleasePool");
 
266
 
 
267
        // Create all the classes we override
 
268
        createAppDelClass();
 
269
        createMyWin();
 
270
        createMyView();
 
271
 
 
272
        // Get our shared NSApplication and start it
 
273
        sendClassMsg("NSApplication", "sharedApplication");
 
274
 
 
275
        if (NSApp == NULL) {
 
276
                fprintf(stderr,"Failed to initialized NSApplication...  terminating...\n");
 
277
                return -1;
 
278
        }
 
279
 
 
280
        /* Set a delegate to create the window */
 
281
        appDelObj = newObject("AppDelegate");
 
282
        sendMsg(NSApp, "setDelegate:", appDelObj);
 
283
 
 
284
// if running on 10.7:
 
285
//      sendMsg(NSApp, "disableRelaunchOnLogin"));
 
286
 
 
287
        /* Call the run loop */
 
288
        sendMsg(NSApp, "run");
 
289
 
 
290
        // detachDrawingThread:toTarget:withObject:
 
291
 
 
292
        /* To terminate:
 
293
        sendMsg(NSApp, "terminate:", self);
 
294
        */
 
295
 
 
296
        /* We're done with the pool */
 
297
    delObject(pool);
 
298
 
 
299
        return EXIT_SUCCESS;
 
300
}
 
301
 
 
302
#ifdef NEVER
 
303
 
 
304
- (void)drawRect:(NSRect)rect
 
305
{
 
306
  NSRect r = NSMakeRect(10, 10, 50, 60);
 
307
  NSBezierPath *bp = [NSBezierPath bezierPathWithRect:r];
 
308
  NSColor *color = [NSColor blueColor];
 
309
  [color set];
 
310
  [bp fill];
 
311
}
 
312
 
 
313
#endif