comparison dynamin/gui/window.d @ 12:7a7e5f9bd1ae

Implement invoke() and invokeNow() on Windows.
author Jordan Miner <jminer7@gmail.com>
date Sat, 18 Jul 2009 01:37:06 -0500
parents 4029d5af7542
children d55b5b998412
comparison
equal deleted inserted replaced
11:df1c8e659b75 12:7a7e5f9bd1ae
35 import dynamin.gui.events; 35 import dynamin.gui.events;
36 import tango.io.Stdout; 36 import tango.io.Stdout;
37 import tango.core.Exception; 37 import tango.core.Exception;
38 import tango.core.Thread; 38 import tango.core.Thread;
39 39
40 ///
40 static class Application { 41 static class Application {
41 static: 42 static:
42 mixin ApplicationBackend; 43 mixin ApplicationBackend;
43 package Thread eventThread; 44 package Thread eventThread;
45 /// Starts event processing. Must be called from main().
44 void run(Window w = null) { 46 void run(Window w = null) {
45 Window.hasProcessedEvents = true; 47 Window.hasProcessedEvents = true;
46 48
47 auto thread = Thread.getThis(); 49 auto thread = Thread.getThis();
48 assert(eventThread is null || eventThread is thread, 50 assert(eventThread is null || eventThread is thread,
49 "Application.run called from two different threads"); 51 "Application.run called from two different threads");
50 eventThread = thread; 52 eventThread = thread;
51 53
52 backend_run(w); 54 backend_run(w);
53 } 55 }
54 //void invoke(void delegate() dg) { 56 /**
55 // 57 * Calls the specified delegate on the event thread and returns without
56 //} 58 * waiting for the delegate to finish. Since the delegate is not called
57 //void invokeNow(void delegate() dg) 59 * immediately, it must not live on the stack. Instead, it could be a
60 * method of a class. In D2, delegates generally are on the heap.
61 */
62 void invoke(void delegate() dg) {
63 backend_invoke(dg);
64 }
65 /**
66 * Calls the specified delegate on the event thread and blocks until
67 * the delegate finishes.
68 */
69 void invokeNow(void delegate() dg) {
70 backend_invokeNow(dg);
71 }
58 } 72 }
59 73
74 ///
60 enum DialogResult { 75 enum DialogResult {
61 /// 76 ///
62 OK, 77 OK,
63 /// 78 ///
64 Yes, 79 Yes,
221 typeof(_handle) handle() { 236 typeof(_handle) handle() {
222 if(!handleCreated) 237 if(!handleCreated)
223 recreateHandle(); 238 recreateHandle();
224 assert(Thread.getThis() is Application.eventThread || 239 assert(Thread.getThis() is Application.eventThread ||
225 Application.eventThread is null, 240 Application.eventThread is null,
226 "controls must be accessed and changed only on the event thread"); 241 "Controls must be accessed and changed only on the event thread. Use invokeNow() from other threads.");
227 return _handle; 242 return _handle;
228 } 243 }
229 244
230 bool handleCreated() { return backend_handleCreated; } 245 bool handleCreated() { return backend_handleCreated; }
231 246