Mercurial > dwindows
comparison mac/dw.m @ 731:6a589a1a42b0
Add dw_window_get_font()
Add incomplete dw_scrollbox_get* functions
Add initial QNX Photon support
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 15 Mar 2011 01:46:41 +0000 |
parents | d3fb3613726a |
children | db3a173e487e |
comparison
equal
deleted
inserted
replaced
730:d3fb3613726a | 731:6a589a1a42b0 |
---|---|
7 * | 7 * |
8 * Using garbage collection so requires 10.5 or later. | 8 * Using garbage collection so requires 10.5 or later. |
9 * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit -fobjc-gc-only | 9 * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit -fobjc-gc-only |
10 */ | 10 */ |
11 #import <Cocoa/Cocoa.h> | 11 #import <Cocoa/Cocoa.h> |
12 #import <WebKit/WebKit.h> | 12 #import <WebKit/WebKit.h> |
13 #include "dw.h" | 13 #include "dw.h" |
14 #include <sys/utsname.h> | 14 #include <sys/utsname.h> |
15 #include <sys/socket.h> | 15 #include <sys/socket.h> |
16 #include <sys/un.h> | 16 #include <sys/un.h> |
17 #include <sys/mman.h> | 17 #include <sys/mman.h> |
183 int (*keypressfunc)(HWND, char, int, int, void *) = handler->signalfunction; | 183 int (*keypressfunc)(HWND, char, int, int, void *) = handler->signalfunction; |
184 NSString *nchar = [event charactersIgnoringModifiers]; | 184 NSString *nchar = [event charactersIgnoringModifiers]; |
185 int special = (int)[event modifierFlags]; | 185 int special = (int)[event modifierFlags]; |
186 unichar vk = [nchar characterAtIndex:0]; | 186 unichar vk = [nchar characterAtIndex:0]; |
187 char ch; | 187 char ch; |
188 | 188 |
189 /* Handle a valid key */ | 189 /* Handle a valid key */ |
190 if([nchar length] == 1) | 190 if([nchar length] == 1) |
191 { | 191 { |
192 const char *tmp = [nchar UTF8String]; | 192 const char *tmp = [nchar UTF8String]; |
193 if(tmp) | 193 if(tmp) |
194 { | 194 { |
195 ch = tmp[0]; | 195 ch = tmp[0]; |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 return keypressfunc(handler->window, ch, (int)vk, special, handler->data); | 199 return keypressfunc(handler->window, ch, (int)vk, special, handler->data); |
200 } | 200 } |
201 /* Button press and release event */ | 201 /* Button press and release event */ |
202 case 3: | 202 case 3: |
203 case 4: | 203 case 4: |
205 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; | 205 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; |
206 int button = (int)event; | 206 int button = (int)event; |
207 LONG x,y; | 207 LONG x,y; |
208 | 208 |
209 dw_pointer_query_pos(&x, &y); | 209 dw_pointer_query_pos(&x, &y); |
210 | 210 |
211 return buttonfunc(object, (int)x, (int)y, button, handler->data); | 211 return buttonfunc(object, (int)x, (int)y, button, handler->data); |
212 } | 212 } |
213 /* Window close event */ | 213 /* Window close event */ |
214 case 6: | 214 case 6: |
215 { | 215 { |
240 } | 240 } |
241 /* Container class selection event */ | 241 /* Container class selection event */ |
242 case 9: | 242 case 9: |
243 { | 243 { |
244 int (*containerselectfunc)(HWND, char *, void *) = handler->signalfunction; | 244 int (*containerselectfunc)(HWND, char *, void *) = handler->signalfunction; |
245 | 245 |
246 return containerselectfunc(handler->window, (char *)event, handler->data); | 246 return containerselectfunc(handler->window, (char *)event, handler->data); |
247 } | 247 } |
248 /* Container context menu event */ | 248 /* Container context menu event */ |
249 case 10: | 249 case 10: |
250 { | 250 { |
261 case 11: | 261 case 11: |
262 case 14: | 262 case 14: |
263 { | 263 { |
264 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction; | 264 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction; |
265 int selected = (int)event; | 265 int selected = (int)event; |
266 | 266 |
267 return valuechangedfunc(handler->window, selected, handler->data);; | 267 return valuechangedfunc(handler->window, selected, handler->data);; |
268 } | 268 } |
269 /* Tree class selection event */ | 269 /* Tree class selection event */ |
270 case 12: | 270 case 12: |
271 { | 271 { |
272 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction; | 272 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction; |
273 char *text = (char *)event; | 273 char *text = (char *)event; |
274 void *user = NULL; | 274 void *user = NULL; |
275 id item = nil; | 275 id item = nil; |
276 | 276 |
277 if([object isKindOfClass:[NSOutlineView class]]) | 277 if([object isKindOfClass:[NSOutlineView class]]) |
278 { | 278 { |
279 item = (id)event; | 279 item = (id)event; |
280 NSString *nstr = [item pointerAtIndex:1]; | 280 NSString *nstr = [item pointerAtIndex:1]; |
281 | 281 |
282 if(nstr) | 282 if(nstr) |
283 { | 283 { |
284 text = strdup([nstr UTF8String]); | 284 text = strdup([nstr UTF8String]); |
285 } | 285 } |
286 else | 286 else |
300 } | 300 } |
301 /* Set Focus event */ | 301 /* Set Focus event */ |
302 case 13: | 302 case 13: |
303 { | 303 { |
304 int (* API setfocusfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; | 304 int (* API setfocusfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
305 | 305 |
306 return setfocusfunc(handler->window, handler->data); | 306 return setfocusfunc(handler->window, handler->data); |
307 } | 307 } |
308 /* Notebook page change event */ | 308 /* Notebook page change event */ |
309 case 15: | 309 case 15: |
310 { | 310 { |
311 int (* API switchpagefunc)(HWND, unsigned long, void *) = (int (* API)(HWND, unsigned long, void *))handler->signalfunction; | 311 int (* API switchpagefunc)(HWND, unsigned long, void *) = (int (* API)(HWND, unsigned long, void *))handler->signalfunction; |
312 int pageid = (int)event; | 312 int pageid = (int)event; |
313 | 313 |
314 return switchpagefunc(handler->window, pageid, handler->data); | 314 return switchpagefunc(handler->window, pageid, handler->data); |
315 } | 315 } |
316 case 16: | 316 case 16: |
317 { | 317 { |
318 int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))handler->signalfunction; | 318 int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))handler->signalfunction; |
319 | 319 |
320 return treeexpandfunc(handler->window, (HTREEITEM)event, handler->data); | 320 return treeexpandfunc(handler->window, (HTREEITEM)event, handler->data); |
321 } | 321 } |
322 } | 322 } |
323 } | 323 } |
324 return -1; | 324 return -1; |
366 -(void)doBitBlt:(id)param; | 366 -(void)doBitBlt:(id)param; |
367 -(void)doFlush:(id)param; | 367 -(void)doFlush:(id)param; |
368 @end | 368 @end |
369 | 369 |
370 @implementation DWObject | 370 @implementation DWObject |
371 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ } | 371 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ } |
372 -(void)synchronizeThread:(id)param | 372 -(void)synchronizeThread:(id)param |
373 { | 373 { |
374 pthread_mutex_unlock(DWRunMutex); | 374 pthread_mutex_unlock(DWRunMutex); |
375 pthread_mutex_lock(DWThreadMutex2); | 375 pthread_mutex_lock(DWThreadMutex2); |
376 pthread_mutex_unlock(DWThreadMutex2); | 376 pthread_mutex_unlock(DWThreadMutex2); |
380 { | 380 { |
381 NSValue *bi = (NSValue *)param; | 381 NSValue *bi = (NSValue *)param; |
382 DWBitBlt *bltinfo = (DWBitBlt *)[bi pointerValue]; | 382 DWBitBlt *bltinfo = (DWBitBlt *)[bi pointerValue]; |
383 id bltdest = bltinfo->dest; | 383 id bltdest = bltinfo->dest; |
384 id bltsrc = bltinfo->src; | 384 id bltsrc = bltinfo->src; |
385 | 385 |
386 if([bltdest isMemberOfClass:[NSImage class]]) | 386 if([bltdest isMemberOfClass:[NSImage class]]) |
387 { | 387 { |
388 [bltdest lockFocus]; | 388 [bltdest lockFocus]; |
389 } | 389 } |
390 else | 390 else |
393 _DWLastDrawable = bltinfo->dest; | 393 _DWLastDrawable = bltinfo->dest; |
394 } | 394 } |
395 if([bltsrc isMemberOfClass:[NSImage class]]) | 395 if([bltsrc isMemberOfClass:[NSImage class]]) |
396 { | 396 { |
397 NSImage *image = bltsrc; | 397 NSImage *image = bltsrc; |
398 [image drawAtPoint:NSMakePoint(bltinfo->xdest, bltinfo->ydest) fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height) | 398 [image drawAtPoint:NSMakePoint(bltinfo->xdest, bltinfo->ydest) fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height) |
399 operation:NSCompositeCopy fraction:1.0]; | 399 operation:NSCompositeCopy fraction:1.0]; |
400 [bltsrc release]; | 400 [bltsrc release]; |
401 } | 401 } |
402 [bltdest unlockFocus]; | 402 [bltdest unlockFocus]; |
403 free(bltinfo); | 403 free(bltinfo); |
416 DWObject *DWObj; | 416 DWObject *DWObj; |
417 | 417 |
418 /* So basically to implement our event handlers... | 418 /* So basically to implement our event handlers... |
419 * it looks like we are going to have to subclass | 419 * it looks like we are going to have to subclass |
420 * basically everything. Was hoping to add methods | 420 * basically everything. Was hoping to add methods |
421 * to the superclasses but it looks like you can | 421 * to the superclasses but it looks like you can |
422 * only add methods and no variables, which isn't | 422 * only add methods and no variables, which isn't |
423 * going to work. -Brian | 423 * going to work. -Brian |
424 */ | 424 */ |
425 | 425 |
426 /* Subclass for a box type */ | 426 /* Subclass for a box type */ |
427 @interface DWBox : NSView | 427 @interface DWBox : NSView |
428 #ifdef BUILDING_FOR_SNOW_LEOPARD | 428 #ifdef BUILDING_FOR_SNOW_LEOPARD |
429 <NSWindowDelegate> | 429 <NSWindowDelegate> |
430 #endif | 430 #endif |
431 { | 431 { |
432 Box *box; | 432 Box *box; |
433 void *userdata; | 433 void *userdata; |
434 NSColor *bgcolor; | 434 NSColor *bgcolor; |
435 } | 435 } |
436 -(id)init; | 436 -(id)init; |
437 -(void)dealloc; | 437 -(void)dealloc; |
438 -(Box *)box; | 438 -(Box *)box; |
439 -(void *)userdata; | 439 -(void *)userdata; |
440 -(void)setUserdata:(void *)input; | 440 -(void)setUserdata:(void *)input; |
441 -(void)drawRect:(NSRect)rect; | 441 -(void)drawRect:(NSRect)rect; |
442 -(BOOL)isFlipped; | 442 -(BOOL)isFlipped; |
449 -(void)keyDown:(NSEvent *)theEvent; | 449 -(void)keyDown:(NSEvent *)theEvent; |
450 -(void)setColor:(unsigned long)input; | 450 -(void)setColor:(unsigned long)input; |
451 @end | 451 @end |
452 | 452 |
453 @implementation DWBox | 453 @implementation DWBox |
454 -(id)init | 454 -(id)init |
455 { | 455 { |
456 self = [super init]; | 456 self = [super init]; |
457 | 457 |
458 if (self) | 458 if (self) |
459 { | 459 { |
460 box = calloc(1, sizeof(Box)); | 460 box = calloc(1, sizeof(Box)); |
461 } | 461 } |
462 return self; | 462 return self; |
463 } | 463 } |
464 -(void)dealloc | 464 -(void)dealloc |
465 { | 465 { |
466 UserData *root = userdata; | 466 UserData *root = userdata; |
467 free(box); | 467 free(box); |
468 _remove_userdata(&root, NULL, TRUE); | 468 _remove_userdata(&root, NULL, TRUE); |
469 [super dealloc]; | 469 [super dealloc]; |
470 } | 470 } |
471 -(Box *)box { return box; } | 471 -(Box *)box { return box; } |
472 -(void *)userdata { return userdata; } | 472 -(void *)userdata { return userdata; } |
473 -(void)setUserdata:(void *)input { userdata = input; } | 473 -(void)setUserdata:(void *)input { userdata = input; } |
474 -(void)drawRect:(NSRect)rect | 474 -(void)drawRect:(NSRect)rect |
475 { | 475 { |
476 if(bgcolor) | 476 if(bgcolor) |
477 { | 477 { |
478 [bgcolor set]; | 478 [bgcolor set]; |
479 NSRectFill( [self bounds] ); | 479 NSRectFill( [self bounds] ); |
499 } | 499 } |
500 } | 500 } |
501 @end | 501 @end |
502 | 502 |
503 /* Subclass for a top-level window */ | 503 /* Subclass for a top-level window */ |
504 @interface DWView : DWBox | 504 @interface DWView : DWBox |
505 { | 505 { |
506 NSMenu *windowmenu; | 506 NSMenu *windowmenu; |
507 } | 507 } |
508 -(BOOL)windowShouldClose:(id)sender; | 508 -(BOOL)windowShouldClose:(id)sender; |
509 -(void)setMenu:(NSMenu *)input; | 509 -(void)setMenu:(NSMenu *)input; |
511 -(void)menuHandler:(id)sender; | 511 -(void)menuHandler:(id)sender; |
512 -(void)keyDown:(NSEvent *)theEvent; | 512 -(void)keyDown:(NSEvent *)theEvent; |
513 @end | 513 @end |
514 | 514 |
515 @implementation DWView | 515 @implementation DWView |
516 -(BOOL)windowShouldClose:(id)sender | 516 -(BOOL)windowShouldClose:(id)sender |
517 { | 517 { |
518 if(_event_handler(self, nil, 6) == FALSE) | 518 if(_event_handler(self, nil, 6) == FALSE) |
519 return NO; | 519 return NO; |
520 return YES; | 520 return YES; |
521 } | 521 } |
539 { | 539 { |
540 if(windowmenu) | 540 if(windowmenu) |
541 { | 541 { |
542 [DWApp setMainMenu:windowmenu]; | 542 [DWApp setMainMenu:windowmenu]; |
543 } | 543 } |
544 else | 544 else |
545 { | 545 { |
546 [DWApp setMainMenu:DWMainMenu]; | 546 [DWApp setMainMenu:DWMainMenu]; |
547 } | 547 } |
548 _event_handler(self, nil, 13); | 548 _event_handler(self, nil, 13); |
549 } | 549 } |
553 @end | 553 @end |
554 | 554 |
555 /* Subclass for a button type */ | 555 /* Subclass for a button type */ |
556 @interface DWButton : NSButton | 556 @interface DWButton : NSButton |
557 { | 557 { |
558 void *userdata; | 558 void *userdata; |
559 } | 559 } |
560 -(void *)userdata; | 560 -(void *)userdata; |
561 -(void)setUserdata:(void *)input; | 561 -(void)setUserdata:(void *)input; |
562 -(void)buttonClicked:(id)sender; | 562 -(void)buttonClicked:(id)sender; |
563 @end | 563 @end |
570 @end | 570 @end |
571 | 571 |
572 /* Subclass for a progress type */ | 572 /* Subclass for a progress type */ |
573 @interface DWPercent : NSProgressIndicator | 573 @interface DWPercent : NSProgressIndicator |
574 { | 574 { |
575 void *userdata; | 575 void *userdata; |
576 } | 576 } |
577 -(void *)userdata; | 577 -(void *)userdata; |
578 -(void)setUserdata:(void *)input; | 578 -(void)setUserdata:(void *)input; |
579 @end | 579 @end |
580 | 580 |
585 @end | 585 @end |
586 | 586 |
587 /* Subclass for a entryfield type */ | 587 /* Subclass for a entryfield type */ |
588 @interface DWEntryField : NSTextField | 588 @interface DWEntryField : NSTextField |
589 { | 589 { |
590 void *userdata; | 590 void *userdata; |
591 } | 591 } |
592 -(void *)userdata; | 592 -(void *)userdata; |
593 -(void)setUserdata:(void *)input; | 593 -(void)setUserdata:(void *)input; |
594 @end | 594 @end |
595 | 595 |
600 @end | 600 @end |
601 | 601 |
602 /* Subclass for a entryfield password type */ | 602 /* Subclass for a entryfield password type */ |
603 @interface DWEntryFieldPassword : NSSecureTextField | 603 @interface DWEntryFieldPassword : NSSecureTextField |
604 { | 604 { |
605 void *userdata; | 605 void *userdata; |
606 } | 606 } |
607 -(void *)userdata; | 607 -(void *)userdata; |
608 -(void)setUserdata:(void *)input; | 608 -(void)setUserdata:(void *)input; |
609 @end | 609 @end |
610 | 610 |
613 -(void)setUserdata:(void *)input { userdata = input; } | 613 -(void)setUserdata:(void *)input { userdata = input; } |
614 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 614 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
615 @end | 615 @end |
616 | 616 |
617 /* Subclass for a Notebook control type */ | 617 /* Subclass for a Notebook control type */ |
618 @interface DWNotebook : NSTabView | 618 @interface DWNotebook : NSTabView |
619 #ifdef BUILDING_FOR_SNOW_LEOPARD | 619 #ifdef BUILDING_FOR_SNOW_LEOPARD |
620 <NSTabViewDelegate> | 620 <NSTabViewDelegate> |
621 #endif | 621 #endif |
622 { | 622 { |
623 void *userdata; | 623 void *userdata; |
671 -(void)setPageid:(int)input { pageid = input; } | 671 -(void)setPageid:(int)input { pageid = input; } |
672 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 672 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
673 @end | 673 @end |
674 | 674 |
675 /* Subclass for a color chooser type */ | 675 /* Subclass for a color chooser type */ |
676 @interface DWColorChoose : NSColorPanel | 676 @interface DWColorChoose : NSColorPanel |
677 { | 677 { |
678 DWDialog *dialog; | 678 DWDialog *dialog; |
679 } | 679 } |
680 -(void)changeColor:(id)sender; | 680 -(void)changeColor:(id)sender; |
681 -(void)setDialog:(DWDialog *)input; | 681 -(void)setDialog:(DWDialog *)input; |
688 } | 688 } |
689 -(void)setDialog:(DWDialog *)input { dialog = input; } | 689 -(void)setDialog:(DWDialog *)input { dialog = input; } |
690 @end | 690 @end |
691 | 691 |
692 /* Subclass for a splitbar type */ | 692 /* Subclass for a splitbar type */ |
693 @interface DWSplitBar : NSSplitView | 693 @interface DWSplitBar : NSSplitView |
694 #ifdef BUILDING_FOR_SNOW_LEOPARD | 694 #ifdef BUILDING_FOR_SNOW_LEOPARD |
695 <NSSplitViewDelegate> | 695 <NSSplitViewDelegate> |
696 #endif | 696 #endif |
697 { | 697 { |
698 void *userdata; | 698 void *userdata; |
699 float percent; | 699 float percent; |
700 } | 700 } |
701 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification; | 701 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification; |
702 -(void *)userdata; | 702 -(void *)userdata; |
703 -(void)setUserdata:(void *)input; | 703 -(void)setUserdata:(void *)input; |
730 @end | 730 @end |
731 | 731 |
732 /* Subclass for a slider type */ | 732 /* Subclass for a slider type */ |
733 @interface DWSlider : NSSlider | 733 @interface DWSlider : NSSlider |
734 { | 734 { |
735 void *userdata; | 735 void *userdata; |
736 } | 736 } |
737 -(void *)userdata; | 737 -(void *)userdata; |
738 -(void)setUserdata:(void *)input; | 738 -(void)setUserdata:(void *)input; |
739 -(void)sliderChanged:(id)sender; | 739 -(void)sliderChanged:(id)sender; |
740 @end | 740 @end |
765 -(void *)userdata { return userdata; } | 765 -(void *)userdata { return userdata; } |
766 -(void)setUserdata:(void *)input { userdata = input; } | 766 -(void)setUserdata:(void *)input { userdata = input; } |
767 -(float)range { return range; } | 767 -(float)range { return range; } |
768 -(float)visible { return visible; } | 768 -(float)visible { return visible; } |
769 -(void)setRange:(float)input1 andVisible:(float)input2 { range = input1; visible = input2; } | 769 -(void)setRange:(float)input1 andVisible:(float)input2 { range = input1; visible = input2; } |
770 -(void)scrollerChanged:(id)sender | 770 -(void)scrollerChanged:(id)sender |
771 { | 771 { |
772 double proportion = [self knobProportion]; | 772 double proportion = [self knobProportion]; |
773 int page = (int)(proportion * range); | 773 int page = (int)(proportion * range); |
774 int max = (int)(range - page); | 774 int max = (int)(range - page); |
775 int result = (int)([self doubleValue] * max); | 775 int result = (int)([self doubleValue] * max); |
776 int newpos = result; | 776 int newpos = result; |
777 | 777 |
778 switch ([sender hitPart]) | 778 switch ([sender hitPart]) |
779 { | 779 { |
780 | 780 |
781 case NSScrollerDecrementLine: | 781 case NSScrollerDecrementLine: |
782 if(newpos > 0) | 782 if(newpos > 0) |
783 { | 783 { |
784 newpos--; | 784 newpos--; |
785 } | 785 } |
786 break; | 786 break; |
787 | 787 |
788 case NSScrollerIncrementLine: | 788 case NSScrollerIncrementLine: |
789 if(newpos < max) | 789 if(newpos < max) |
790 { | 790 { |
791 newpos++; | 791 newpos++; |
792 } | 792 } |
793 break; | 793 break; |
794 | 794 |
795 case NSScrollerDecrementPage: | 795 case NSScrollerDecrementPage: |
796 newpos -= page; | 796 newpos -= page; |
797 if(newpos < 0) | 797 if(newpos < 0) |
798 { | 798 { |
799 newpos = 0; | 799 newpos = 0; |
800 } | 800 } |
801 break; | 801 break; |
802 | 802 |
803 case NSScrollerIncrementPage: | 803 case NSScrollerIncrementPage: |
804 newpos += page; | 804 newpos += page; |
805 if(newpos > max) | 805 if(newpos > max) |
806 { | 806 { |
807 newpos = max; | 807 newpos = max; |
808 } | 808 } |
809 break; | 809 break; |
810 | 810 |
811 default: | 811 default: |
812 ; // do nothing | 812 ; // do nothing |
813 } | 813 } |
814 if(newpos != result) | 814 if(newpos != result) |
815 { | 815 { |
816 double newposd = (double)newpos/max; | 816 double newposd = (double)newpos/max; |
817 [self setDoubleValue:newposd]; | 817 [self setDoubleValue:newposd]; |
818 } | 818 } |
819 _event_handler(self, (void *)newpos, 14); | 819 _event_handler(self, (void *)newpos, 14); |
820 } | 820 } |
821 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 821 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
822 @end | 822 @end |
823 | 823 |
824 /* Subclass for a render area type */ | 824 /* Subclass for a render area type */ |
825 @interface DWRender : NSView | 825 @interface DWRender : NSView |
826 { | 826 { |
827 void *userdata; | 827 void *userdata; |
828 } | 828 } |
829 -(void *)userdata; | 829 -(void *)userdata; |
830 -(void)setUserdata:(void *)input; | 830 -(void)setUserdata:(void *)input; |
853 -(BOOL)isFlipped { return NO; } | 853 -(BOOL)isFlipped { return NO; } |
854 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 854 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
855 @end | 855 @end |
856 | 856 |
857 /* Subclass for a MLE type */ | 857 /* Subclass for a MLE type */ |
858 @interface DWMLE : NSTextView | 858 @interface DWMLE : NSTextView |
859 { | 859 { |
860 void *userdata; | 860 void *userdata; |
861 } | 861 } |
862 -(void *)userdata; | 862 -(void *)userdata; |
863 -(void)setUserdata:(void *)input; | 863 -(void)setUserdata:(void *)input; |
868 -(void)setUserdata:(void *)input { userdata = input; } | 868 -(void)setUserdata:(void *)input { userdata = input; } |
869 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 869 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
870 @end | 870 @end |
871 | 871 |
872 /* Subclass for a Container/List type */ | 872 /* Subclass for a Container/List type */ |
873 @interface DWContainer : NSTableView | 873 @interface DWContainer : NSTableView |
874 #ifdef BUILDING_FOR_SNOW_LEOPARD | 874 #ifdef BUILDING_FOR_SNOW_LEOPARD |
875 <NSTableViewDataSource> | 875 <NSTableViewDataSource> |
876 #endif | 876 #endif |
877 { | 877 { |
878 void *userdata; | 878 void *userdata; |
952 -(void)setUserdata:(void *)input { userdata = input; } | 952 -(void)setUserdata:(void *)input { userdata = input; } |
953 -(id)scrollview { return scrollview; } | 953 -(id)scrollview { return scrollview; } |
954 -(void)setScrollview:(id)input { scrollview = input; } | 954 -(void)setScrollview:(id)input { scrollview = input; } |
955 -(void)addColumn:(NSTableColumn *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } } | 955 -(void)addColumn:(NSTableColumn *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } } |
956 -(NSTableColumn *)getColumn:(int)col { if(tvcols) { return [tvcols objectAtIndex:col]; } return nil; } | 956 -(NSTableColumn *)getColumn:(int)col { if(tvcols) { return [tvcols objectAtIndex:col]; } return nil; } |
957 -(int)insertRow:(NSArray *)input at:(int)index | 957 -(int)insertRow:(NSArray *)input at:(int)index |
958 { | 958 { |
959 if(data) | 959 if(data) |
960 { | 960 { |
961 unsigned long start = [tvcols count] * index; | 961 unsigned long start = [tvcols count] * index; |
962 NSIndexSet *set = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(start, start + [tvcols count])]; | 962 NSIndexSet *set = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(start, start + [tvcols count])]; |
963 if(index < lastAddPoint) | 963 if(index < lastAddPoint) |
964 { | 964 { |
965 lastAddPoint++; | 965 lastAddPoint++; |
966 } | 966 } |
967 [data insertObjects:input atIndexes:set]; | 967 [data insertObjects:input atIndexes:set]; |
968 [titles insertPointer:NULL atIndex:index]; | 968 [titles insertPointer:NULL atIndex:index]; |
969 [set release]; | 969 [set release]; |
970 return (int)[titles count]; | 970 return (int)[titles count]; |
971 } | 971 } |
972 return 0; | 972 return 0; |
973 } | 973 } |
974 -(int)addRow:(NSArray *)input | 974 -(int)addRow:(NSArray *)input |
975 { | 975 { |
976 if(data) | 976 if(data) |
977 { | 977 { |
978 lastAddPoint = (int)[titles count]; | 978 lastAddPoint = (int)[titles count]; |
979 [data addObjectsFromArray:input]; | 979 [data addObjectsFromArray:input]; |
980 [titles addPointer:NULL]; | 980 [titles addPointer:NULL]; |
981 return (int)[titles count]; | 981 return (int)[titles count]; |
982 } | 982 } |
983 return 0; | 983 return 0; |
984 } | 984 } |
985 -(int)addRows:(int)number | 985 -(int)addRows:(int)number |
986 { | 986 { |
987 if(tvcols) | 987 if(tvcols) |
988 { | 988 { |
1038 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } | 1038 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } |
1039 -(int)lastAddPoint { return lastAddPoint; } | 1039 -(int)lastAddPoint { return lastAddPoint; } |
1040 -(int)lastQueryPoint { return lastQueryPoint; } | 1040 -(int)lastQueryPoint { return lastQueryPoint; } |
1041 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } | 1041 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } |
1042 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } | 1042 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } |
1043 -(void)setup | 1043 -(void)setup |
1044 { | 1044 { |
1045 tvcols = [[[NSMutableArray alloc] init] retain]; | 1045 tvcols = [[[NSMutableArray alloc] init] retain]; |
1046 data = [[[NSMutableArray alloc] init] retain]; | 1046 data = [[[NSMutableArray alloc] init] retain]; |
1047 types = [[[NSMutableArray alloc] init] retain]; | 1047 types = [[[NSMutableArray alloc] init] retain]; |
1048 titles = [[NSPointerArray pointerArrayWithWeakObjects] retain]; | 1048 titles = [[NSPointerArray pointerArrayWithWeakObjects] retain]; |
1049 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:[self window]]; | 1049 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:[self window]]; |
1050 } | 1050 } |
1051 -(void)doubleClicked:(id)sender | 1051 -(void)doubleClicked:(id)sender |
1052 { | 1052 { |
1058 /* Handler for container class */ | 1058 /* Handler for container class */ |
1059 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 12); | 1059 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 12); |
1060 /* Handler for listbox class */ | 1060 /* Handler for listbox class */ |
1061 _event_handler(self, (NSEvent *)(int)[self selectedRow], 11); | 1061 _event_handler(self, (NSEvent *)(int)[self selectedRow], 11); |
1062 } | 1062 } |
1063 -(NSMenu *)menuForEvent:(NSEvent *)event | 1063 -(NSMenu *)menuForEvent:(NSEvent *)event |
1064 { | 1064 { |
1065 int row; | 1065 int row; |
1066 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; | 1066 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; |
1067 row = (int)[self rowAtPoint:where]; | 1067 row = (int)[self rowAtPoint:where]; |
1068 _event_handler(self, (NSEvent *)[self getRowTitle:row], 10); | 1068 _event_handler(self, (NSEvent *)[self getRowTitle:row], 10); |
1076 { | 1076 { |
1077 if(node) | 1077 if(node) |
1078 { | 1078 { |
1079 int count = (int)[node count]; | 1079 int count = (int)[node count]; |
1080 int z; | 1080 int z; |
1081 | 1081 |
1082 for(z=0;z<count;z++) | 1082 for(z=0;z<count;z++) |
1083 { | 1083 { |
1084 NSPointerArray *pnt = [node objectAtIndex:z]; | 1084 NSPointerArray *pnt = [node objectAtIndex:z]; |
1085 NSMutableArray *children = (NSMutableArray *)[pnt pointerAtIndex:3]; | 1085 NSMutableArray *children = (NSMutableArray *)[pnt pointerAtIndex:3]; |
1086 | 1086 |
1087 if(children) | 1087 if(children) |
1088 { | 1088 { |
1089 if(item == pnt) | 1089 if(item == pnt) |
1090 { | 1090 { |
1091 _free_tree_recurse(children, NULL); | 1091 _free_tree_recurse(children, NULL); |
1102 [node release]; | 1102 [node release]; |
1103 } | 1103 } |
1104 } | 1104 } |
1105 | 1105 |
1106 /* Subclass for a Tree type */ | 1106 /* Subclass for a Tree type */ |
1107 @interface DWTree : NSOutlineView | 1107 @interface DWTree : NSOutlineView |
1108 #ifdef BUILDING_FOR_SNOW_LEOPARD | 1108 #ifdef BUILDING_FOR_SNOW_LEOPARD |
1109 <NSOutlineViewDataSource> | 1109 <NSOutlineViewDataSource> |
1110 #endif | 1110 #endif |
1111 { | 1111 { |
1112 void *userdata; | 1112 void *userdata; |
1113 NSTableColumn *imagecol; | 1113 NSTableColumn *imagecol; |
1114 NSTableColumn *textcol; | 1114 NSTableColumn *textcol; |
1115 NSMutableArray *data; | 1115 NSMutableArray *data; |
1116 /* Each data item consists of a linked lists of tree item data. | 1116 /* Each data item consists of a linked lists of tree item data. |
1117 * NSImage *, NSString *, Item Data *, NSMutableArray * of Children | 1117 * NSImage *, NSString *, Item Data *, NSMutableArray * of Children |
1118 */ | 1118 */ |
1119 id scrollview; | 1119 id scrollview; |
1120 } | 1120 } |
1121 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item; | 1121 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item; |
1133 -(void)deleteNode:(NSPointerArray *)item; | 1133 -(void)deleteNode:(NSPointerArray *)item; |
1134 -(void)clear; | 1134 -(void)clear; |
1135 @end | 1135 @end |
1136 | 1136 |
1137 @implementation DWTree | 1137 @implementation DWTree |
1138 -(id)init | 1138 -(id)init |
1139 { | 1139 { |
1140 self = [super init]; | 1140 self = [super init]; |
1141 | 1141 |
1142 if (self) | 1142 if (self) |
1143 { | 1143 { |
1144 imagecol = [[NSTableColumn alloc] init]; | 1144 imagecol = [[NSTableColumn alloc] init]; |
1145 NSImageCell *imagecell = [[[NSImageCell alloc] init] autorelease]; | 1145 NSImageCell *imagecell = [[[NSImageCell alloc] init] autorelease]; |
1146 [imagecol setDataCell:imagecell]; | 1146 [imagecol setDataCell:imagecell]; |
1147 [imagecol setResizingMask:NSTableColumnNoResizing]; | 1147 [imagecol setResizingMask:NSTableColumnNoResizing]; |
1155 } | 1155 } |
1156 return self; | 1156 return self; |
1157 } | 1157 } |
1158 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item | 1158 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item |
1159 { | 1159 { |
1160 if(item) | 1160 if(item) |
1161 { | 1161 { |
1162 NSMutableArray *array = [item pointerAtIndex:3]; | 1162 NSMutableArray *array = [item pointerAtIndex:3]; |
1163 return array ? [array objectAtIndex:index] : nil; | 1163 return array ? [array objectAtIndex:index] : nil; |
1164 } | 1164 } |
1165 else | 1165 else |
1184 { | 1184 { |
1185 return 0; | 1185 return 0; |
1186 } | 1186 } |
1187 } | 1187 } |
1188 else | 1188 else |
1189 { | 1189 { |
1190 return data ? (int)[data count] : 0; | 1190 return data ? (int)[data count] : 0; |
1191 } | 1191 } |
1192 } | 1192 } |
1193 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item | 1193 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item |
1194 { | 1194 { |
1195 if(item) | 1195 if(item) |
1196 { | 1196 { |
1197 if([item isKindOfClass:[NSPointerArray class]]) | 1197 if([item isKindOfClass:[NSPointerArray class]]) |
1198 { | 1198 { |
1199 NSPointerArray *this = (NSPointerArray *)item; | 1199 NSPointerArray *this = (NSPointerArray *)item; |
1200 if(tableColumn == imagecol) | 1200 if(tableColumn == imagecol) |
1201 { | 1201 { |
1202 return [this pointerAtIndex:0]; | 1202 return [this pointerAtIndex:0]; |
1203 } | 1203 } |
1204 return [this pointerAtIndex:1]; | 1204 return [this pointerAtIndex:1]; |
1205 } | 1205 } |
1206 else | 1206 else |
1207 { | 1207 { |
1208 return nil; | 1208 return nil; |
1209 } | 1209 } |
1210 } | 1210 } |
1211 return @"List Root"; | 1211 return @"List Root"; |
1212 } | 1212 } |
1242 if(item) | 1242 if(item) |
1243 { | 1243 { |
1244 _event_handler(self, (void *)item, 12); | 1244 _event_handler(self, (void *)item, 12); |
1245 } | 1245 } |
1246 } | 1246 } |
1247 -(void)treeItemExpanded:(NSNotification *)notification | 1247 -(void)treeItemExpanded:(NSNotification *)notification |
1248 { | 1248 { |
1249 id item = [[notification userInfo ] objectForKey: @"NSObject"]; | 1249 id item = [[notification userInfo ] objectForKey: @"NSObject"]; |
1250 | 1250 |
1251 if(item) | 1251 if(item) |
1252 { | 1252 { |
1253 _event_handler(self, (void *)item, 16); | 1253 _event_handler(self, (void *)item, 16); |
1254 } | 1254 } |
1255 } | 1255 } |
1256 -(NSMenu *)menuForEvent:(NSEvent *)event | 1256 -(NSMenu *)menuForEvent:(NSEvent *)event |
1257 { | 1257 { |
1258 int row; | 1258 int row; |
1259 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; | 1259 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; |
1260 row = (int)[self rowAtPoint:where]; | 1260 row = (int)[self rowAtPoint:where]; |
1261 id item = [self itemAtRow:row]; | 1261 id item = [self itemAtRow:row]; |
1265 } | 1265 } |
1266 -(NSScrollView *)scrollview { return scrollview; } | 1266 -(NSScrollView *)scrollview { return scrollview; } |
1267 -(void)setScrollview:(NSScrollView *)input { scrollview = input; } | 1267 -(void)setScrollview:(NSScrollView *)input { scrollview = input; } |
1268 -(void)deleteNode:(NSPointerArray *)item { _free_tree_recurse(data, item); } | 1268 -(void)deleteNode:(NSPointerArray *)item { _free_tree_recurse(data, item); } |
1269 -(void)clear { NSMutableArray *toclear = data; data = nil; _free_tree_recurse(toclear, NULL); [self reloadData]; } | 1269 -(void)clear { NSMutableArray *toclear = data; data = nil; _free_tree_recurse(toclear, NULL); [self reloadData]; } |
1270 -(void)dealloc | 1270 -(void)dealloc |
1271 { | 1271 { |
1272 UserData *root = userdata; | 1272 UserData *root = userdata; |
1273 _remove_userdata(&root, NULL, TRUE); | 1273 _remove_userdata(&root, NULL, TRUE); |
1274 _free_tree_recurse(data, NULL); | 1274 _free_tree_recurse(data, NULL); |
1275 [imagecol release]; | 1275 [imagecol release]; |
1276 [textcol release]; | 1276 [textcol release]; |
1277 [super dealloc]; | 1277 [super dealloc]; |
1278 } | 1278 } |
1279 @end | 1279 @end |
1280 | 1280 |
1281 /* Subclass for a Calendar type */ | 1281 /* Subclass for a Calendar type */ |
1282 @interface DWCalendar : NSDatePicker | 1282 @interface DWCalendar : NSDatePicker |
1283 { | 1283 { |
1284 void *userdata; | 1284 void *userdata; |
1285 } | 1285 } |
1286 -(void *)userdata; | 1286 -(void *)userdata; |
1287 -(void)setUserdata:(void *)input; | 1287 -(void)setUserdata:(void *)input; |
1292 -(void)setUserdata:(void *)input { userdata = input; } | 1292 -(void)setUserdata:(void *)input { userdata = input; } |
1293 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 1293 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
1294 @end | 1294 @end |
1295 | 1295 |
1296 /* Subclass for a Combobox type */ | 1296 /* Subclass for a Combobox type */ |
1297 @interface DWComboBox : NSComboBox | 1297 @interface DWComboBox : NSComboBox |
1298 #ifdef BUILDING_FOR_SNOW_LEOPARD | 1298 #ifdef BUILDING_FOR_SNOW_LEOPARD |
1299 <NSComboBoxDelegate> | 1299 <NSComboBoxDelegate> |
1300 #endif | 1300 #endif |
1301 { | 1301 { |
1302 void *userdata; | 1302 void *userdata; |
1313 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 1313 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
1314 @end | 1314 @end |
1315 | 1315 |
1316 /* Subclass for a stepper component of the spinbutton type */ | 1316 /* Subclass for a stepper component of the spinbutton type */ |
1317 /* This is a bad way of doing this... but I can't get the other methods to work */ | 1317 /* This is a bad way of doing this... but I can't get the other methods to work */ |
1318 @interface DWStepper : NSStepper | 1318 @interface DWStepper : NSStepper |
1319 { | 1319 { |
1320 id textfield; | 1320 id textfield; |
1321 id parent; | 1321 id parent; |
1322 } | 1322 } |
1323 -(void)setTextfield:(id)input; | 1323 -(void)setTextfield:(id)input; |
1324 -(id)textfield; | 1324 -(id)textfield; |
1334 -(void)setParent:(id)input { parent = input; } | 1334 -(void)setParent:(id)input { parent = input; } |
1335 -(id)parent { return parent; } | 1335 -(id)parent { return parent; } |
1336 -(void)mouseDown:(NSEvent *)event | 1336 -(void)mouseDown:(NSEvent *)event |
1337 { | 1337 { |
1338 [super mouseDown:event]; | 1338 [super mouseDown:event]; |
1339 if([[NSApp currentEvent] type] == NSLeftMouseUp) | 1339 if([[NSApp currentEvent] type] == NSLeftMouseUp) |
1340 { | 1340 { |
1341 [textfield takeIntValueFrom:self]; | 1341 [textfield takeIntValueFrom:self]; |
1342 _event_handler(parent, (void *)[self integerValue], 14); | 1342 _event_handler(parent, (void *)[self integerValue], 14); |
1343 } | 1343 } |
1344 } | 1344 } |
1345 -(void)mouseUp:(NSEvent *)event | 1345 -(void)mouseUp:(NSEvent *)event |
1346 { | 1346 { |
1347 [textfield takeIntValueFrom:self]; | 1347 [textfield takeIntValueFrom:self]; |
1348 _event_handler(parent, (void *)[self integerValue], 14); | 1348 _event_handler(parent, (void *)[self integerValue], 14); |
1349 } | 1349 } |
1350 @end | 1350 @end |
1351 | 1351 |
1352 /* Subclass for a Spinbutton type */ | 1352 /* Subclass for a Spinbutton type */ |
1353 @interface DWSpinButton : NSView | 1353 @interface DWSpinButton : NSView |
1354 #ifdef BUILDING_FOR_SNOW_LEOPARD | 1354 #ifdef BUILDING_FOR_SNOW_LEOPARD |
1355 <NSTextFieldDelegate> | 1355 <NSTextFieldDelegate> |
1356 #endif | 1356 #endif |
1357 { | 1357 { |
1358 void *userdata; | 1358 void *userdata; |
1366 -(NSStepper *)stepper; | 1366 -(NSStepper *)stepper; |
1367 -(void)controlTextDidChange:(NSNotification *)aNotification; | 1367 -(void)controlTextDidChange:(NSNotification *)aNotification; |
1368 @end | 1368 @end |
1369 | 1369 |
1370 @implementation DWSpinButton | 1370 @implementation DWSpinButton |
1371 -(id)init | 1371 -(id)init |
1372 { | 1372 { |
1373 self = [super init]; | 1373 self = [super init]; |
1374 | 1374 |
1375 if(self) | 1375 if(self) |
1376 { | 1376 { |
1377 textfield = [[NSTextField alloc] init]; | 1377 textfield = [[NSTextField alloc] init]; |
1378 [self addSubview:textfield]; | 1378 [self addSubview:textfield]; |
1379 stepper = [[DWStepper alloc] init]; | 1379 stepper = [[DWStepper alloc] init]; |
1380 [self addSubview:stepper]; | 1380 [self addSubview:stepper]; |
1396 _event_handler(self, (void *)[stepper integerValue], 14); | 1396 _event_handler(self, (void *)[stepper integerValue], 14); |
1397 } | 1397 } |
1398 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 1398 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
1399 @end | 1399 @end |
1400 | 1400 |
1401 /* Subclass for a MDI type | 1401 /* Subclass for a MDI type |
1402 * This is just a box for display purposes... but it is a | 1402 * This is just a box for display purposes... but it is a |
1403 * unique class so it can be identified when creating windows. | 1403 * unique class so it can be identified when creating windows. |
1404 */ | 1404 */ |
1405 @interface DWMDI : DWBox {} | 1405 @interface DWMDI : DWBox {} |
1406 @end | 1406 @end |
1775 if([handle isMemberOfClass:[DWNotebook class]]) | 1775 if([handle isMemberOfClass:[DWNotebook class]]) |
1776 { | 1776 { |
1777 DWNotebook *notebook = (DWNotebook *)handle; | 1777 DWNotebook *notebook = (DWNotebook *)handle; |
1778 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; | 1778 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; |
1779 DWBox *view = [notepage view]; | 1779 DWBox *view = [notepage view]; |
1780 | 1780 |
1781 if(view != nil) | 1781 if(view != nil) |
1782 { | 1782 { |
1783 Box *box = [view box]; | 1783 Box *box = [view box]; |
1784 NSSize size = [view frame].size; | 1784 NSSize size = [view frame].size; |
1785 _do_resize(box, size.width, size.height); | 1785 _do_resize(box, size.width, size.height); |
1802 } | 1802 } |
1803 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) | 1803 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) |
1804 { | 1804 { |
1805 DWSplitBar *split = (DWSplitBar *)handle; | 1805 DWSplitBar *split = (DWSplitBar *)handle; |
1806 float percent = [split percent]; | 1806 float percent = [split percent]; |
1807 | 1807 |
1808 if(percent > 0) | 1808 if(percent > 0) |
1809 { | 1809 { |
1810 dw_splitbar_set(handle, percent); | 1810 dw_splitbar_set(handle, percent); |
1811 [split setPercent:0]; | 1811 [split setPercent:0]; |
1812 } | 1812 } |
1813 } | 1813 } |
1814 | 1814 |
1815 if(thisbox->type == DW_HORZ) | 1815 if(thisbox->type == DW_HORZ) |
1816 currentx += width + vectorx + (pad * 2); | 1816 currentx += width + vectorx + (pad * 2); |
1817 if(thisbox->type == DW_VERT) | 1817 if(thisbox->type == DW_VERT) |
1818 currenty += height + vectory + (pad * 2); | 1818 currenty += height + vectory + (pad * 2); |
1819 } | 1819 } |
1929 * milliseconds: Number of milliseconds to run the loop for. | 1929 * milliseconds: Number of milliseconds to run the loop for. |
1930 */ | 1930 */ |
1931 void API dw_main_sleep(int milliseconds) | 1931 void API dw_main_sleep(int milliseconds) |
1932 { | 1932 { |
1933 DWTID curr = pthread_self(); | 1933 DWTID curr = pthread_self(); |
1934 | 1934 |
1935 if(DWThread == (DWTID)-1 || DWThread == curr) | 1935 if(DWThread == (DWTID)-1 || DWThread == curr) |
1936 { | 1936 { |
1937 DWTID orig = DWThread; | 1937 DWTID orig = DWThread; |
1938 NSDate *until = [NSDate dateWithTimeIntervalSinceNow:(milliseconds/1000.0)]; | 1938 NSDate *until = [NSDate dateWithTimeIntervalSinceNow:(milliseconds/1000.0)]; |
1939 | 1939 |
1940 if(orig == (DWTID)-1) | 1940 if(orig == (DWTID)-1) |
1941 { | 1941 { |
1942 dw_mutex_lock(DWRunMutex); | 1942 dw_mutex_lock(DWRunMutex); |
1943 DWThread = curr; | 1943 DWThread = curr; |
1944 } | 1944 } |
1964 { | 1964 { |
1965 NSEvent *event = [DWApp nextEventMatchingMask:NSAnyEventMask | 1965 NSEvent *event = [DWApp nextEventMatchingMask:NSAnyEventMask |
1966 untilDate:date | 1966 untilDate:date |
1967 inMode:NSDefaultRunLoopMode | 1967 inMode:NSDefaultRunLoopMode |
1968 dequeue:YES]; | 1968 dequeue:YES]; |
1969 if(event) | 1969 if(event) |
1970 { | 1970 { |
1971 [DWApp sendEvent:event]; | 1971 [DWApp sendEvent:event]; |
1972 [DWApp updateWindows]; | 1972 [DWApp updateWindows]; |
1973 return 1; | 1973 return 1; |
1974 } | 1974 } |
1979 * Processes a single message iteration and returns. | 1979 * Processes a single message iteration and returns. |
1980 */ | 1980 */ |
1981 void API dw_main_iteration(void) | 1981 void API dw_main_iteration(void) |
1982 { | 1982 { |
1983 DWTID curr = pthread_self(); | 1983 DWTID curr = pthread_self(); |
1984 | 1984 |
1985 if(DWThread == (DWTID)-1) | 1985 if(DWThread == (DWTID)-1) |
1986 { | 1986 { |
1987 dw_mutex_lock(DWRunMutex); | 1987 dw_mutex_lock(DWRunMutex); |
1988 DWThread = curr; | 1988 DWThread = curr; |
1989 _dw_main_iteration([NSDate distantPast]); | 1989 _dw_main_iteration([NSDate distantPast]); |
2076 } | 2076 } |
2077 | 2077 |
2078 if(flags & DW_MB_ERROR) | 2078 if(flags & DW_MB_ERROR) |
2079 { | 2079 { |
2080 iResponse = (int) | 2080 iResponse = (int) |
2081 NSRunCriticalAlertPanel([ NSString stringWithUTF8String:title ], | 2081 NSRunCriticalAlertPanel([ NSString stringWithUTF8String:title ], |
2082 [ NSString stringWithUTF8String:outbuf ], | 2082 [ NSString stringWithUTF8String:outbuf ], |
2083 button1, button2, button3); } | 2083 button1, button2, button3); } |
2084 else | 2084 else |
2085 { | 2085 { |
2086 iResponse = (int) | 2086 iResponse = (int) |
2087 NSRunAlertPanel([ NSString stringWithUTF8String:title ], | 2087 NSRunAlertPanel([ NSString stringWithUTF8String:title ], |
2088 [ NSString stringWithUTF8String:outbuf ], | 2088 [ NSString stringWithUTF8String:outbuf ], |
2089 button1, button2, button3); | 2089 button1, button2, button3); |
2090 } | 2090 } |
2091 | 2091 |
2092 switch(iResponse) | 2092 switch(iResponse) |
2093 { | 2093 { |
2094 case NSAlertDefaultReturn: /* user pressed OK */ | 2094 case NSAlertDefaultReturn: /* user pressed OK */ |
2095 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) | 2095 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) |
2096 { | 2096 { |
2097 return DW_MB_RETURN_YES; | 2097 return DW_MB_RETURN_YES; |
2273 */ | 2273 */ |
2274 HWND API dw_box_new(int type, int pad) | 2274 HWND API dw_box_new(int type, int pad) |
2275 { | 2275 { |
2276 int _locked_by_me = FALSE; | 2276 int _locked_by_me = FALSE; |
2277 DW_MUTEX_LOCK; | 2277 DW_MUTEX_LOCK; |
2278 DWBox *view = [[DWBox alloc] init]; | 2278 DWBox *view = [[DWBox alloc] init]; |
2279 Box *newbox = [view box]; | 2279 Box *newbox = [view box]; |
2280 memset(newbox, 0, sizeof(Box)); | 2280 memset(newbox, 0, sizeof(Box)); |
2281 newbox->pad = pad; | 2281 newbox->pad = pad; |
2282 newbox->type = type; | 2282 newbox->type = type; |
2283 DW_MUTEX_UNLOCK; | 2283 DW_MUTEX_UNLOCK; |
2295 { | 2295 { |
2296 DWBox *box = dw_box_new(type, pad); | 2296 DWBox *box = dw_box_new(type, pad); |
2297 [box setFocusRingType:NSFocusRingTypeExterior]; | 2297 [box setFocusRingType:NSFocusRingTypeExterior]; |
2298 return box; | 2298 return box; |
2299 } | 2299 } |
2300 | |
2301 #ifndef INCOMPLETE | |
2302 /* | |
2303 * Create a new scrollable Box to be packed. | |
2304 * Parameters: | |
2305 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). | |
2306 * pad: Number of pixels to pad around the box. | |
2307 * This works fine under GTK+, but is incomplete on other platforms | |
2308 */ | |
2309 HWND dw_scrollbox_new( int type, int pad ) | |
2310 { | |
2311 DWBox *box = dw_box_new(type, pad); | |
2312 [box setFocusRingType:NSFocusRingTypeExterior]; | |
2313 NSLog(@"dw_scrollbox_new() unimplemented\n"); | |
2314 return box; | |
2315 } | |
2316 | |
2317 /* | |
2318 * Returns the position of the scrollbar in the scrollbox | |
2319 * Parameters: | |
2320 * handle: Handle to the scrollbox to be queried. | |
2321 * orient: The vertical or horizontal scrollbar. | |
2322 */ | |
2323 int dw_scrollbox_get_pos(HWND handle, int orient) | |
2324 { | |
2325 int val = -1; | |
2326 NSLog(@"dw_scrollbox_get_pos() unimplemented\n"); | |
2327 return val; | |
2328 } | |
2329 | |
2330 /* | |
2331 * Gets the range for the scrollbar in the scrollbox. | |
2332 * Parameters: | |
2333 * handle: Handle to the scrollbox to be queried. | |
2334 * orient: The vertical or horizontal scrollbar. | |
2335 */ | |
2336 int API dw_scrollbox_get_range(HWND handle, int orient) | |
2337 { | |
2338 int val = -1; | |
2339 NSLog(@"dw_scrollbox_get_range() unimplemented\n"); | |
2340 return val; | |
2341 } | |
2342 #endif | |
2300 | 2343 |
2301 /* | 2344 /* |
2302 * Pack windows (widgets) into a box from the end (or bottom). | 2345 * Pack windows (widgets) into a box from the end (or bottom). |
2303 * Parameters: | 2346 * Parameters: |
2304 * box: Window handle of the box to be packed into. | 2347 * box: Window handle of the box to be packed into. |
2340 else if([ object isKindOfClass:[ DWTree class ] ]) | 2383 else if([ object isKindOfClass:[ DWTree class ] ]) |
2341 { | 2384 { |
2342 DWTree *tree = item; | 2385 DWTree *tree = item; |
2343 this = item = [tree scrollview]; | 2386 this = item = [tree scrollview]; |
2344 } | 2387 } |
2345 | 2388 |
2346 /* Duplicate the existing data */ | 2389 /* Duplicate the existing data */ |
2347 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | 2390 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
2348 | 2391 |
2349 for(z=0;z<thisbox->count;z++) | 2392 for(z=0;z<thisbox->count;z++) |
2350 { | 2393 { |
2564 HWND API dw_bitmapbutton_new(char *text, ULONG resid) | 2607 HWND API dw_bitmapbutton_new(char *text, ULONG resid) |
2565 { | 2608 { |
2566 /* TODO: Implement tooltips */ | 2609 /* TODO: Implement tooltips */ |
2567 NSBundle *bundle = [NSBundle mainBundle]; | 2610 NSBundle *bundle = [NSBundle mainBundle]; |
2568 NSString *respath = [bundle resourcePath]; | 2611 NSString *respath = [bundle resourcePath]; |
2569 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; | 2612 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; |
2570 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; | 2613 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; |
2571 DWButton *button = _button_new("", resid); | 2614 DWButton *button = _button_new("", resid); |
2572 [button setImage:image]; | 2615 [button setImage:image]; |
2573 //[button setBezelStyle:0]; | 2616 //[button setBezelStyle:0]; |
2574 [button setButtonType:NSMomentaryLight]; | 2617 [button setButtonType:NSMomentaryLight]; |
2750 else | 2793 else |
2751 { | 2794 { |
2752 scrollbar = [[DWScrollbar alloc] initWithFrame:NSMakeRect(0,0,100,5)]; | 2795 scrollbar = [[DWScrollbar alloc] initWithFrame:NSMakeRect(0,0,100,5)]; |
2753 } | 2796 } |
2754 [scrollbar setArrowsPosition:NSScrollerArrowsDefaultSetting]; | 2797 [scrollbar setArrowsPosition:NSScrollerArrowsDefaultSetting]; |
2755 [scrollbar setTarget:scrollbar]; | 2798 [scrollbar setTarget:scrollbar]; |
2756 [scrollbar setAction:@selector(changed:)]; | 2799 [scrollbar setAction:@selector(changed:)]; |
2757 [scrollbar setRange:0.0 andVisible:0.0]; | 2800 [scrollbar setRange:0.0 andVisible:0.0]; |
2758 [scrollbar setKnobProportion:1.0]; | 2801 [scrollbar setKnobProportion:1.0]; |
2759 [scrollbar setTarget:scrollbar]; | 2802 [scrollbar setTarget:scrollbar]; |
2760 [scrollbar setAction:@selector(scrollerChanged:)]; | 2803 [scrollbar setAction:@selector(scrollerChanged:)]; |
2875 DWButton *button = handle; | 2918 DWButton *button = handle; |
2876 if(value) | 2919 if(value) |
2877 { | 2920 { |
2878 [button setState:NSOnState]; | 2921 [button setState:NSOnState]; |
2879 } | 2922 } |
2880 else | 2923 else |
2881 { | 2924 { |
2882 [button setState:NSOffState]; | 2925 [button setState:NSOffState]; |
2883 } | 2926 } |
2884 | 2927 |
2885 } | 2928 } |
2886 | 2929 |
2887 /* Common code for containers and listboxes */ | 2930 /* Common code for containers and listboxes */ |
2888 HWND _cont_new(ULONG cid, int multi) | 2931 HWND _cont_new(ULONG cid, int multi) |
2889 { | 2932 { |
2890 NSScrollView *scrollview = [[NSScrollView alloc] init]; | 2933 NSScrollView *scrollview = [[NSScrollView alloc] init]; |
2891 DWContainer *cont = [[DWContainer alloc] init]; | 2934 DWContainer *cont = [[DWContainer alloc] init]; |
2892 | 2935 |
2893 [cont setScrollview:scrollview]; | 2936 [cont setScrollview:scrollview]; |
2894 [scrollview setBorderType:NSBezelBorder]; | 2937 [scrollview setBorderType:NSBezelBorder]; |
2895 [scrollview setHasVerticalScroller:YES]; | 2938 [scrollview setHasVerticalScroller:YES]; |
2896 [scrollview setAutohidesScrollers:YES]; | 2939 [scrollview setAutohidesScrollers:YES]; |
2897 | 2940 |
2898 if(multi) | 2941 if(multi) |
2899 { | 2942 { |
2900 [cont setAllowsMultipleSelection:YES]; | 2943 [cont setAllowsMultipleSelection:YES]; |
2901 } | 2944 } |
2902 else | 2945 else |
2953 else if([object isMemberOfClass:[DWContainer class]]) | 2996 else if([object isMemberOfClass:[DWContainer class]]) |
2954 { | 2997 { |
2955 DWContainer *cont = handle; | 2998 DWContainer *cont = handle; |
2956 NSString *nstr = [ NSString stringWithUTF8String:text ]; | 2999 NSString *nstr = [ NSString stringWithUTF8String:text ]; |
2957 NSArray *newrow = [NSArray arrayWithObject:nstr]; | 3000 NSArray *newrow = [NSArray arrayWithObject:nstr]; |
2958 | 3001 |
2959 [cont addRow:newrow]; | 3002 [cont addRow:newrow]; |
2960 /*[cont performSelectorOnMainThread:@selector(addRow:) | 3003 /*[cont performSelectorOnMainThread:@selector(addRow:) |
2961 withObject:newrow | 3004 withObject:newrow |
2962 waitUntilDone:YES];*/ | 3005 waitUntilDone:YES];*/ |
2963 [cont reloadData]; | 3006 [cont reloadData]; |
2987 else if([object isMemberOfClass:[DWContainer class]]) | 3030 else if([object isMemberOfClass:[DWContainer class]]) |
2988 { | 3031 { |
2989 DWContainer *cont = handle; | 3032 DWContainer *cont = handle; |
2990 NSString *nstr = [ NSString stringWithUTF8String:text ]; | 3033 NSString *nstr = [ NSString stringWithUTF8String:text ]; |
2991 NSArray *newrow = [NSArray arrayWithObject:nstr]; | 3034 NSArray *newrow = [NSArray arrayWithObject:nstr]; |
2992 | 3035 |
2993 [cont insertRow:newrow at:pos]; | 3036 [cont insertRow:newrow at:pos]; |
2994 [cont reloadData]; | 3037 [cont reloadData]; |
2995 } | 3038 } |
2996 DW_MUTEX_UNLOCK; | 3039 DW_MUTEX_UNLOCK; |
2997 } | 3040 } |
3026 | 3069 |
3027 for(z=0;z<count;z++) | 3070 for(z=0;z<count;z++) |
3028 { | 3071 { |
3029 NSString *nstr = [ NSString stringWithUTF8String:text[z] ]; | 3072 NSString *nstr = [ NSString stringWithUTF8String:text[z] ]; |
3030 NSArray *newrow = [[NSArray alloc] arrayWithObject:nstr]; | 3073 NSArray *newrow = [[NSArray alloc] arrayWithObject:nstr]; |
3031 | 3074 |
3032 [cont addRow:newrow]; | 3075 [cont addRow:newrow]; |
3033 } | 3076 } |
3034 [cont reloadData]; | 3077 [cont reloadData]; |
3035 } | 3078 } |
3036 DW_MUTEX_UNLOCK; | 3079 DW_MUTEX_UNLOCK; |
3054 [combo removeAllItems]; | 3097 [combo removeAllItems]; |
3055 } | 3098 } |
3056 else if([object isMemberOfClass:[DWContainer class]]) | 3099 else if([object isMemberOfClass:[DWContainer class]]) |
3057 { | 3100 { |
3058 DWContainer *cont = handle; | 3101 DWContainer *cont = handle; |
3059 | 3102 |
3060 [cont clear]; | 3103 [cont clear]; |
3061 [cont reloadData]; | 3104 [cont reloadData]; |
3062 } | 3105 } |
3063 DW_MUTEX_UNLOCK; | 3106 DW_MUTEX_UNLOCK; |
3064 } | 3107 } |
3109 [combo scrollItemAtIndexToTop:top]; | 3152 [combo scrollItemAtIndexToTop:top]; |
3110 } | 3153 } |
3111 else if([object isMemberOfClass:[DWContainer class]]) | 3154 else if([object isMemberOfClass:[DWContainer class]]) |
3112 { | 3155 { |
3113 DWContainer *cont = handle; | 3156 DWContainer *cont = handle; |
3114 | 3157 |
3115 [cont scrollRowToVisible:top]; | 3158 [cont scrollRowToVisible:top]; |
3116 } | 3159 } |
3117 DW_MUTEX_UNLOCK; | 3160 DW_MUTEX_UNLOCK; |
3118 } | 3161 } |
3119 | 3162 |
3133 | 3176 |
3134 if([object isMemberOfClass:[DWComboBox class]]) | 3177 if([object isMemberOfClass:[DWComboBox class]]) |
3135 { | 3178 { |
3136 DWComboBox *combo = handle; | 3179 DWComboBox *combo = handle; |
3137 int count = (int)[combo numberOfItems]; | 3180 int count = (int)[combo numberOfItems]; |
3138 | 3181 |
3139 if(index > count) | 3182 if(index > count) |
3140 { | 3183 { |
3141 *buffer = '\0'; | 3184 *buffer = '\0'; |
3142 } | 3185 } |
3143 else | 3186 else |
3148 } | 3191 } |
3149 else if([object isMemberOfClass:[DWContainer class]]) | 3192 else if([object isMemberOfClass:[DWContainer class]]) |
3150 { | 3193 { |
3151 DWContainer *cont = handle; | 3194 DWContainer *cont = handle; |
3152 int count = (int)[cont numberOfRowsInTableView:cont]; | 3195 int count = (int)[cont numberOfRowsInTableView:cont]; |
3153 | 3196 |
3154 if(index > count) | 3197 if(index > count) |
3155 { | 3198 { |
3156 *buffer = '\0'; | 3199 *buffer = '\0'; |
3157 } | 3200 } |
3158 else | 3201 else |
3159 { | 3202 { |
3160 NSString *nstr = [cont getRow:index and:0]; | 3203 NSString *nstr = [cont getRow:index and:0]; |
3161 | 3204 |
3162 strncpy(buffer, [ nstr UTF8String ], length - 1); | 3205 strncpy(buffer, [ nstr UTF8String ], length - 1); |
3163 } | 3206 } |
3164 } | 3207 } |
3165 DW_MUTEX_UNLOCK; | 3208 DW_MUTEX_UNLOCK; |
3166 } | 3209 } |
3191 } | 3234 } |
3192 else if([object isMemberOfClass:[DWContainer class]]) | 3235 else if([object isMemberOfClass:[DWContainer class]]) |
3193 { | 3236 { |
3194 DWContainer *cont = handle; | 3237 DWContainer *cont = handle; |
3195 int count = (int)[cont numberOfRowsInTableView:cont]; | 3238 int count = (int)[cont numberOfRowsInTableView:cont]; |
3196 | 3239 |
3197 if(index <= count) | 3240 if(index <= count) |
3198 { | 3241 { |
3199 NSString *nstr = [ NSString stringWithUTF8String:buffer ]; | 3242 NSString *nstr = [ NSString stringWithUTF8String:buffer ]; |
3200 | 3243 |
3201 [cont editCell:nstr at:index and:0]; | 3244 [cont editCell:nstr at:index and:0]; |
3202 [cont reloadData]; | 3245 [cont reloadData]; |
3203 } | 3246 } |
3204 } | 3247 } |
3205 DW_MUTEX_UNLOCK; | 3248 DW_MUTEX_UNLOCK; |
3206 } | 3249 } |
3207 | 3250 |
3208 /* | 3251 /* |
3209 * Returns the index to the item in the list currently selected. | 3252 * Returns the index to the item in the list currently selected. |
3210 * Parameters: | 3253 * Parameters: |
3241 { | 3284 { |
3242 int _locked_by_me = FALSE; | 3285 int _locked_by_me = FALSE; |
3243 DW_MUTEX_LOCK; | 3286 DW_MUTEX_LOCK; |
3244 id object = handle; | 3287 id object = handle; |
3245 int retval = -1; | 3288 int retval = -1; |
3246 | 3289 |
3247 if([object isMemberOfClass:[DWContainer class]]) | 3290 if([object isMemberOfClass:[DWContainer class]]) |
3248 { | 3291 { |
3249 DWContainer *cont = handle; | 3292 DWContainer *cont = handle; |
3250 NSIndexSet *selected = [cont selectedRowIndexes]; | 3293 NSIndexSet *selected = [cont selectedRowIndexes]; |
3251 NSUInteger result = [selected indexGreaterThanIndex:where]; | 3294 NSUInteger result = [selected indexGreaterThanIndex:where]; |
3252 | 3295 |
3253 if(result != NSNotFound) | 3296 if(result != NSNotFound) |
3254 { | 3297 { |
3255 retval = (int)result; | 3298 retval = (int)result; |
3256 } | 3299 } |
3257 } | 3300 } |
3258 DW_MUTEX_UNLOCK; | 3301 DW_MUTEX_UNLOCK; |
3259 return retval; | 3302 return retval; |
3260 } | 3303 } |
3261 | 3304 |
3262 /* | 3305 /* |
3282 } | 3325 } |
3283 else if([object isMemberOfClass:[DWContainer class]]) | 3326 else if([object isMemberOfClass:[DWContainer class]]) |
3284 { | 3327 { |
3285 DWContainer *cont = handle; | 3328 DWContainer *cont = handle; |
3286 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)index]; | 3329 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)index]; |
3287 | 3330 |
3288 [cont selectRowIndexes:selected byExtendingSelection:YES]; | 3331 [cont selectRowIndexes:selected byExtendingSelection:YES]; |
3289 [selected release]; | 3332 [selected release]; |
3290 } | 3333 } |
3291 DW_MUTEX_UNLOCK; | 3334 DW_MUTEX_UNLOCK; |
3292 } | 3335 } |
3293 | 3336 |
3294 /* | 3337 /* |
3295 * Deletes the item with given index from the list. | 3338 * Deletes the item with given index from the list. |
3310 [combo removeItemAtIndex:index]; | 3353 [combo removeItemAtIndex:index]; |
3311 } | 3354 } |
3312 else if([object isMemberOfClass:[DWContainer class]]) | 3355 else if([object isMemberOfClass:[DWContainer class]]) |
3313 { | 3356 { |
3314 DWContainer *cont = handle; | 3357 DWContainer *cont = handle; |
3315 | 3358 |
3316 [cont removeRow:index]; | 3359 [cont removeRow:index]; |
3317 [cont reloadData]; | 3360 [cont reloadData]; |
3318 } | 3361 } |
3319 DW_MUTEX_UNLOCK; | 3362 DW_MUTEX_UNLOCK; |
3320 } | 3363 } |
3339 * id: An ID to be used with dw_window_from_id() or 0L. | 3382 * id: An ID to be used with dw_window_from_id() or 0L. |
3340 */ | 3383 */ |
3341 HWND API dw_mle_new(ULONG cid) | 3384 HWND API dw_mle_new(ULONG cid) |
3342 { | 3385 { |
3343 DWMLE *mle = [[DWMLE alloc] init]; | 3386 DWMLE *mle = [[DWMLE alloc] init]; |
3344 NSScrollView *scrollview = [[NSScrollView alloc] init]; | 3387 NSScrollView *scrollview = [[NSScrollView alloc] init]; |
3345 | 3388 |
3346 //[mle setScrollview:scrollview]; | 3389 //[mle setScrollview:scrollview]; |
3347 [scrollview setBorderType:NSBezelBorder]; | 3390 [scrollview setBorderType:NSBezelBorder]; |
3348 [scrollview setHasVerticalScroller:YES]; | 3391 [scrollview setHasVerticalScroller:YES]; |
3349 [scrollview setAutohidesScrollers:YES]; | 3392 [scrollview setAutohidesScrollers:YES]; |
3350 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; | 3393 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; |
3401 { | 3444 { |
3402 NSScrollView *sv = handle; | 3445 NSScrollView *sv = handle; |
3403 DWMLE *mle = [sv documentView]; | 3446 DWMLE *mle = [sv documentView]; |
3404 NSTextStorage *ts = [mle textStorage]; | 3447 NSTextStorage *ts = [mle textStorage]; |
3405 NSMutableString *ms = [ts mutableString]; | 3448 NSMutableString *ms = [ts mutableString]; |
3406 | 3449 |
3407 *bytes = [ms length]; | 3450 *bytes = [ms length]; |
3408 *lines = 0; /* TODO: Line count */ | 3451 *lines = 0; /* TODO: Line count */ |
3409 } | 3452 } |
3410 | 3453 |
3411 /* | 3454 /* |
3465 DWMLE *mle = [sv documentView]; | 3508 DWMLE *mle = [sv documentView]; |
3466 if(state) | 3509 if(state) |
3467 { | 3510 { |
3468 [mle setEditable:YES]; | 3511 [mle setEditable:YES]; |
3469 } | 3512 } |
3470 else | 3513 else |
3471 { | 3514 { |
3472 [mle setEditable:NO]; | 3515 [mle setEditable:NO]; |
3473 } | 3516 } |
3474 } | 3517 } |
3475 | 3518 |
3627 DWDialog *dialog = dw_dialog_new(colorDlg); | 3670 DWDialog *dialog = dw_dialog_new(colorDlg); |
3628 | 3671 |
3629 /* Set defaults for the dialog. */ | 3672 /* Set defaults for the dialog. */ |
3630 [colorDlg setColor:color]; | 3673 [colorDlg setColor:color]; |
3631 [colorDlg setDialog:dialog]; | 3674 [colorDlg setDialog:dialog]; |
3632 [colorDlg setContinuous:YES]; | 3675 [colorDlg setContinuous:YES]; |
3633 [colorDlg setTarget:colorDlg]; | 3676 [colorDlg setTarget:colorDlg]; |
3634 [colorDlg setAction:@selector(changeColor:)]; | 3677 [colorDlg setAction:@selector(changeColor:)]; |
3635 [colorDlg makeKeyAndOrderFront:nil]; | 3678 [colorDlg makeKeyAndOrderFront:nil]; |
3636 | 3679 |
3637 color = (NSColor *)dw_dialog_wait(dialog); | 3680 color = (NSColor *)dw_dialog_wait(dialog); |
3638 [color release]; | 3681 [color release]; |
3639 return _foreground; | 3682 return _foreground; |
3886 */ | 3929 */ |
3887 HWND API dw_tree_new(ULONG cid) | 3930 HWND API dw_tree_new(ULONG cid) |
3888 { | 3931 { |
3889 int _locked_by_me = FALSE; | 3932 int _locked_by_me = FALSE; |
3890 DW_MUTEX_LOCK; | 3933 DW_MUTEX_LOCK; |
3891 NSScrollView *scrollview = [[NSScrollView alloc] init]; | 3934 NSScrollView *scrollview = [[NSScrollView alloc] init]; |
3892 DWTree *tree = [[DWTree alloc] init]; | 3935 DWTree *tree = [[DWTree alloc] init]; |
3893 | 3936 |
3894 [tree setScrollview:scrollview]; | 3937 [tree setScrollview:scrollview]; |
3895 [scrollview setBorderType:NSBezelBorder]; | 3938 [scrollview setBorderType:NSBezelBorder]; |
3896 [scrollview setHasVerticalScroller:YES]; | 3939 [scrollview setHasVerticalScroller:YES]; |
3897 [scrollview setAutohidesScrollers:YES]; | 3940 [scrollview setAutohidesScrollers:YES]; |
3898 | 3941 |
3899 [tree setAllowsMultipleSelection:NO]; | 3942 [tree setAllowsMultipleSelection:NO]; |
3900 [tree setDataSource:tree]; | 3943 [tree setDataSource:tree]; |
3901 [scrollview setDocumentView:tree]; | 3944 [scrollview setDocumentView:tree]; |
3902 [tree setHeaderView:nil]; | 3945 [tree setHeaderView:nil]; |
3903 [tree setTag:cid]; | 3946 [tree setTag:cid]; |
4237 DW_MUTEX_LOCK; | 4280 DW_MUTEX_LOCK; |
4238 DWContainer *cont = handle; | 4281 DWContainer *cont = handle; |
4239 id object = nil; | 4282 id object = nil; |
4240 int type = [cont cellType:column]; | 4283 int type = [cont cellType:column]; |
4241 int lastadd = [cont lastAddPoint]; | 4284 int lastadd = [cont lastAddPoint]; |
4242 | 4285 |
4243 if(!data) | 4286 if(!data) |
4244 { | 4287 { |
4245 DW_MUTEX_UNLOCK; | 4288 DW_MUTEX_UNLOCK; |
4246 return; | 4289 return; |
4247 } | 4290 } |
4252 else if(type & DW_CFA_STRING) | 4295 else if(type & DW_CFA_STRING) |
4253 { | 4296 { |
4254 char *str = *((char **)data); | 4297 char *str = *((char **)data); |
4255 object = [ NSString stringWithUTF8String:str ]; | 4298 object = [ NSString stringWithUTF8String:str ]; |
4256 } | 4299 } |
4257 else | 4300 else |
4258 { | 4301 { |
4259 char textbuffer[100]; | 4302 char textbuffer[100]; |
4260 | 4303 |
4261 if(type & DW_CFA_ULONG) | 4304 if(type & DW_CFA_ULONG) |
4262 { | 4305 { |
4286 curtm.tm_min = ctime.minutes; | 4329 curtm.tm_min = ctime.minutes; |
4287 curtm.tm_sec = ctime.seconds; | 4330 curtm.tm_sec = ctime.seconds; |
4288 | 4331 |
4289 strftime(textbuffer, 100, "%X", &curtm); | 4332 strftime(textbuffer, 100, "%X", &curtm); |
4290 } | 4333 } |
4291 else | 4334 else |
4292 { | 4335 { |
4293 DW_MUTEX_UNLOCK; | 4336 DW_MUTEX_UNLOCK; |
4294 return; | 4337 return; |
4295 } | 4338 } |
4296 object = [ NSString stringWithUTF8String:textbuffer ]; | 4339 object = [ NSString stringWithUTF8String:textbuffer ]; |
4421 { | 4464 { |
4422 int _locked_by_me = FALSE; | 4465 int _locked_by_me = FALSE; |
4423 DW_MUTEX_LOCK; | 4466 DW_MUTEX_LOCK; |
4424 DWContainer *cont = handle; | 4467 DWContainer *cont = handle; |
4425 NSTableColumn *col = [cont getColumn:column]; | 4468 NSTableColumn *col = [cont getColumn:column]; |
4426 | 4469 |
4427 [col setWidth:width]; | 4470 [col setWidth:width]; |
4428 DW_MUTEX_UNLOCK; | 4471 DW_MUTEX_UNLOCK; |
4429 } | 4472 } |
4430 | 4473 |
4431 /* | 4474 /* |
4489 { | 4532 { |
4490 int _locked_by_me = FALSE; | 4533 int _locked_by_me = FALSE; |
4491 DW_MUTEX_LOCK; | 4534 DW_MUTEX_LOCK; |
4492 DWContainer *cont = handle; | 4535 DWContainer *cont = handle; |
4493 int x; | 4536 int x; |
4494 | 4537 |
4495 for(x=0;x<rowcount;x++) | 4538 for(x=0;x<rowcount;x++) |
4496 { | 4539 { |
4497 [cont removeRow:0]; | 4540 [cont removeRow:0]; |
4498 } | 4541 } |
4499 DW_MUTEX_UNLOCK; | 4542 DW_MUTEX_UNLOCK; |
4526 DW_MUTEX_LOCK; | 4569 DW_MUTEX_LOCK; |
4527 DWContainer *cont = handle; | 4570 DWContainer *cont = handle; |
4528 NSIndexSet *selected = [cont selectedRowIndexes]; | 4571 NSIndexSet *selected = [cont selectedRowIndexes]; |
4529 NSUInteger result = [selected indexGreaterThanOrEqualToIndex:0]; | 4572 NSUInteger result = [selected indexGreaterThanOrEqualToIndex:0]; |
4530 char *retval = NULL; | 4573 char *retval = NULL; |
4531 | 4574 |
4532 if(result != NSNotFound) | 4575 if(result != NSNotFound) |
4533 { | 4576 { |
4534 retval = [cont getRowTitle:(int)result]; | 4577 retval = [cont getRowTitle:(int)result]; |
4535 [cont setLastQueryPoint:(int)result]; | 4578 [cont setLastQueryPoint:(int)result]; |
4536 } | 4579 } |
4553 DWContainer *cont = handle; | 4596 DWContainer *cont = handle; |
4554 int lastQueryPoint = [cont lastQueryPoint]; | 4597 int lastQueryPoint = [cont lastQueryPoint]; |
4555 NSIndexSet *selected = [cont selectedRowIndexes]; | 4598 NSIndexSet *selected = [cont selectedRowIndexes]; |
4556 NSUInteger result = [selected indexGreaterThanIndex:lastQueryPoint]; | 4599 NSUInteger result = [selected indexGreaterThanIndex:lastQueryPoint]; |
4557 char *retval = NULL; | 4600 char *retval = NULL; |
4558 | 4601 |
4559 if(result != NSNotFound) | 4602 if(result != NSNotFound) |
4560 { | 4603 { |
4561 retval = [cont getRowTitle:(int)result]; | 4604 retval = [cont getRowTitle:(int)result]; |
4562 [cont setLastQueryPoint:(int)result]; | 4605 [cont setLastQueryPoint:(int)result]; |
4563 } | 4606 } |
4576 int _locked_by_me = FALSE; | 4619 int _locked_by_me = FALSE; |
4577 DW_MUTEX_LOCK; | 4620 DW_MUTEX_LOCK; |
4578 DWContainer *cont = handle; | 4621 DWContainer *cont = handle; |
4579 char *thistext; | 4622 char *thistext; |
4580 int x, count = (int)[cont numberOfRowsInTableView:cont]; | 4623 int x, count = (int)[cont numberOfRowsInTableView:cont]; |
4581 | 4624 |
4582 for(x=0;x<count;x++) | 4625 for(x=0;x<count;x++) |
4583 { | 4626 { |
4584 thistext = [cont getRowTitle:x]; | 4627 thistext = [cont getRowTitle:x]; |
4585 | 4628 |
4586 if(thistext == text) | 4629 if(thistext == text) |
4587 { | 4630 { |
4588 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x]; | 4631 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x]; |
4589 | 4632 |
4590 [cont selectRowIndexes:selected byExtendingSelection:YES]; | 4633 [cont selectRowIndexes:selected byExtendingSelection:YES]; |
4591 [selected release]; | 4634 [selected release]; |
4592 } | 4635 } |
4593 } | 4636 } |
4594 DW_MUTEX_UNLOCK; | 4637 DW_MUTEX_UNLOCK; |
4605 int _locked_by_me = FALSE; | 4648 int _locked_by_me = FALSE; |
4606 DW_MUTEX_LOCK; | 4649 DW_MUTEX_LOCK; |
4607 DWContainer *cont = handle; | 4650 DWContainer *cont = handle; |
4608 char *thistext; | 4651 char *thistext; |
4609 int x, count = (int)[cont numberOfRowsInTableView:cont]; | 4652 int x, count = (int)[cont numberOfRowsInTableView:cont]; |
4610 | 4653 |
4611 for(x=0;x<count;x++) | 4654 for(x=0;x<count;x++) |
4612 { | 4655 { |
4613 thistext = [cont getRowTitle:x]; | 4656 thistext = [cont getRowTitle:x]; |
4614 | 4657 |
4615 if(thistext == text) | 4658 if(thistext == text) |
4616 { | 4659 { |
4617 [cont removeRow:x]; | 4660 [cont removeRow:x]; |
4618 return; | 4661 return; |
4619 } | 4662 } |
4669 */ | 4712 */ |
4670 HICN API dw_icon_load(unsigned long module, unsigned long resid) | 4713 HICN API dw_icon_load(unsigned long module, unsigned long resid) |
4671 { | 4714 { |
4672 NSBundle *bundle = [NSBundle mainBundle]; | 4715 NSBundle *bundle = [NSBundle mainBundle]; |
4673 NSString *respath = [bundle resourcePath]; | 4716 NSString *respath = [bundle resourcePath]; |
4674 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; | 4717 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; |
4675 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; | 4718 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; |
4676 return image; | 4719 return image; |
4677 } | 4720 } |
4678 | 4721 |
4679 /* | 4722 /* |
4728 HWND API dw_mdi_new(unsigned long cid) | 4771 HWND API dw_mdi_new(unsigned long cid) |
4729 { | 4772 { |
4730 /* There isn't anything like quite like MDI on MacOS... | 4773 /* There isn't anything like quite like MDI on MacOS... |
4731 * However we will make floating windows that hide | 4774 * However we will make floating windows that hide |
4732 * when the application is deactivated to simulate | 4775 * when the application is deactivated to simulate |
4733 * similar behavior. | 4776 * similar behavior. |
4734 */ | 4777 */ |
4735 DWMDI *mdi = [[DWMDI alloc] init]; | 4778 DWMDI *mdi = [[DWMDI alloc] init]; |
4736 /* [mdi setTag:cid]; Why doesn't this work? */ | 4779 /* [mdi setTag:cid]; Why doesn't this work? */ |
4737 return mdi; | 4780 return mdi; |
4738 } | 4781 } |
4746 * Returns: | 4789 * Returns: |
4747 * A handle to a splitbar window or NULL on failure. | 4790 * A handle to a splitbar window or NULL on failure. |
4748 */ | 4791 */ |
4749 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid) | 4792 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid) |
4750 { | 4793 { |
4751 HWND tmpbox = dw_box_new(DW_VERT, 0); | 4794 HWND tmpbox = dw_box_new(DW_VERT, 0); |
4752 int _locked_by_me = FALSE; | 4795 int _locked_by_me = FALSE; |
4753 DW_MUTEX_LOCK; | 4796 DW_MUTEX_LOCK; |
4754 DWSplitBar *split = [[DWSplitBar alloc] init]; | 4797 DWSplitBar *split = [[DWSplitBar alloc] init]; |
4755 [split setDelegate:split]; | 4798 [split setDelegate:split]; |
4756 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); | 4799 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); |
4757 [split addSubview:tmpbox]; | 4800 [split addSubview:tmpbox]; |
4758 tmpbox = dw_box_new(DW_VERT, 0); | 4801 tmpbox = dw_box_new(DW_VERT, 0); |
4759 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); | 4802 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); |
4760 [split addSubview:tmpbox]; | 4803 [split addSubview:tmpbox]; |
4761 if(type == DW_VERT) | 4804 if(type == DW_VERT) |
4762 { | 4805 { |
4763 [split setVertical:NO]; | 4806 [split setVertical:NO]; |
4797 [split setPosition:pos ofDividerAtIndex:0]; | 4840 [split setPosition:pos ofDividerAtIndex:0]; |
4798 } | 4841 } |
4799 else | 4842 else |
4800 { | 4843 { |
4801 /* If we have no size.. wait until the resize | 4844 /* If we have no size.. wait until the resize |
4802 * event when we get an actual size to try | 4845 * event when we get an actual size to try |
4803 * to set the splitbar again. | 4846 * to set the splitbar again. |
4804 */ | 4847 */ |
4805 [split setPercent:percent]; | 4848 [split setPercent:percent]; |
4806 } | 4849 } |
4807 DW_MUTEX_UNLOCK; | 4850 DW_MUTEX_UNLOCK; |
4953 { | 4996 { |
4954 HPIXMAP pixmap; | 4997 HPIXMAP pixmap; |
4955 | 4998 |
4956 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 4999 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
4957 return NULL; | 5000 return NULL; |
4958 | 5001 |
4959 NSBundle *bundle = [NSBundle mainBundle]; | 5002 NSBundle *bundle = [NSBundle mainBundle]; |
4960 NSString *respath = [bundle resourcePath]; | 5003 NSString *respath = [bundle resourcePath]; |
4961 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; | 5004 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; |
4962 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; | 5005 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; |
4963 NSSize size = [image size]; | 5006 NSSize size = [image size]; |
4964 pixmap->width = size.width; | 5007 pixmap->width = size.width; |
4965 pixmap->height = size.height; | 5008 pixmap->height = size.height; |
4966 pixmap->handle = image; | 5009 pixmap->handle = image; |
4997 */ | 5040 */ |
4998 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) | 5041 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) |
4999 { | 5042 { |
5000 DWBitBlt *bltinfo = calloc(1, sizeof(DWBitBlt)); | 5043 DWBitBlt *bltinfo = calloc(1, sizeof(DWBitBlt)); |
5001 NSValue* bi = [NSValue valueWithPointer:bltinfo]; | 5044 NSValue* bi = [NSValue valueWithPointer:bltinfo]; |
5002 | 5045 |
5003 /* Fill in the information */ | 5046 /* Fill in the information */ |
5004 bltinfo->dest = dest; | 5047 bltinfo->dest = dest; |
5005 bltinfo->src = src; | 5048 bltinfo->src = src; |
5006 bltinfo->xdest = xdest; | 5049 bltinfo->xdest = xdest; |
5007 bltinfo->ydest = ydest; | 5050 bltinfo->ydest = ydest; |
5008 bltinfo->width = width; | 5051 bltinfo->width = width; |
5009 bltinfo->height = height; | 5052 bltinfo->height = height; |
5010 bltinfo->xsrc = xsrc; | 5053 bltinfo->xsrc = xsrc; |
5011 bltinfo->ysrc = ysrc; | 5054 bltinfo->ysrc = ysrc; |
5012 | 5055 |
5013 if(destp) | 5056 if(destp) |
5014 { | 5057 { |
5015 bltinfo->dest = (id)destp->handle; | 5058 bltinfo->dest = (id)destp->handle; |
5016 } | 5059 } |
5017 if(srcp) | 5060 if(srcp) |
5018 { | 5061 { |
5019 id object = bltinfo->src = (id)srcp->handle; | 5062 id object = bltinfo->src = (id)srcp->handle; |
5020 [object retain]; | 5063 [object retain]; |
5021 } | 5064 } |
5022 [DWObj performSelectorOnMainThread:@selector(doBitBlt:) withObject:bi waitUntilDone:YES]; | 5065 [DWObj performSelectorOnMainThread:@selector(doBitBlt:) withObject:bi waitUntilDone:YES]; |
5023 } | 5066 } |
5024 | 5067 |
5025 /* | 5068 /* |
5026 * Create a new static text window (widget) to be packed. | 5069 * Create a new static text window (widget) to be packed. |
5169 * x: Pointer to variable to store X coordinate. | 5212 * x: Pointer to variable to store X coordinate. |
5170 * y: Pointer to variable to store Y coordinate. | 5213 * y: Pointer to variable to store Y coordinate. |
5171 */ | 5214 */ |
5172 void API dw_pointer_query_pos(long *x, long *y) | 5215 void API dw_pointer_query_pos(long *x, long *y) |
5173 { | 5216 { |
5174 NSPoint mouseLoc; | 5217 NSPoint mouseLoc; |
5175 mouseLoc = [NSEvent mouseLocation]; | 5218 mouseLoc = [NSEvent mouseLocation]; |
5176 if(x) | 5219 if(x) |
5177 { | 5220 { |
5178 *x = mouseLoc.x; | 5221 *x = mouseLoc.x; |
5179 } | 5222 } |
5245 NSMenu *thismenu = (NSMenu *)*menu; | 5288 NSMenu *thismenu = (NSMenu *)*menu; |
5246 id object = parent; | 5289 id object = parent; |
5247 NSView *view = [object isKindOfClass:[NSWindow class]] ? [object contentView] : parent; | 5290 NSView *view = [object isKindOfClass:[NSWindow class]] ? [object contentView] : parent; |
5248 NSWindow *window = [view window]; | 5291 NSWindow *window = [view window]; |
5249 NSEvent *event = [DWApp currentEvent]; | 5292 NSEvent *event = [DWApp currentEvent]; |
5250 NSEvent* fake = [NSEvent mouseEventWithType:NSRightMouseDown | 5293 NSEvent* fake = [NSEvent mouseEventWithType:NSRightMouseDown |
5251 location:[window convertScreenToBase:NSMakePoint(x, y)] | 5294 location:[window convertScreenToBase:NSMakePoint(x, y)] |
5252 modifierFlags:0 | 5295 modifierFlags:0 |
5253 timestamp:[event timestamp] | 5296 timestamp:[event timestamp] |
5254 windowNumber:[window windowNumber] | 5297 windowNumber:[window windowNumber] |
5255 context:[NSGraphicsContext currentContext] | 5298 context:[NSGraphicsContext currentContext] |
5256 eventNumber:1 | 5299 eventNumber:1 |
5257 clickCount:1 | 5300 clickCount:1 |
5258 pressure:0.0]; | 5301 pressure:0.0]; |
5259 [NSMenu popUpContextMenu:thismenu withEvent:fake forView:view]; | 5302 [NSMenu popUpContextMenu:thismenu withEvent:fake forView:view]; |
5260 } | 5303 } |
5261 | 5304 |
5262 char _removetilde(char *dest, char *src) | 5305 char _removetilde(char *dest, char *src) |
5263 { | 5306 { |
5299 NSMenuItem *item = NULL; | 5342 NSMenuItem *item = NULL; |
5300 if(strlen(title) == 0) | 5343 if(strlen(title) == 0) |
5301 { | 5344 { |
5302 [menu addItem:[NSMenuItem separatorItem]]; | 5345 [menu addItem:[NSMenuItem separatorItem]]; |
5303 } | 5346 } |
5304 else | 5347 else |
5305 { | 5348 { |
5306 char accel[2]; | 5349 char accel[2]; |
5307 char *newtitle = malloc(strlen(title)+1); | 5350 char *newtitle = malloc(strlen(title)+1); |
5308 NSString *nstr; | 5351 NSString *nstr; |
5309 | 5352 |
5398 | 5441 |
5399 /* Gets the notebook page from associated ID */ | 5442 /* Gets the notebook page from associated ID */ |
5400 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid) | 5443 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid) |
5401 { | 5444 { |
5402 NSArray *pages = [notebook tabViewItems]; | 5445 NSArray *pages = [notebook tabViewItems]; |
5403 for(DWNotebookPage *notepage in pages) | 5446 for(DWNotebookPage *notepage in pages) |
5404 { | 5447 { |
5405 if([notepage pageid] == pageid) | 5448 if([notepage pageid] == pageid) |
5406 { | 5449 { |
5407 return notepage; | 5450 return notepage; |
5408 } | 5451 } |
5541 | 5584 |
5542 if(notepage != nil) | 5585 if(notepage != nil) |
5543 { | 5586 { |
5544 HWND tmpbox = dw_box_new(DW_VERT, 0); | 5587 HWND tmpbox = dw_box_new(DW_VERT, 0); |
5545 DWBox *box = tmpbox; | 5588 DWBox *box = tmpbox; |
5546 | 5589 |
5547 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); | 5590 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); |
5548 [notepage setView:box]; | 5591 [notepage setView:box]; |
5549 } | 5592 } |
5550 } | 5593 } |
5551 | 5594 |
5576 [window makeKeyAndOrderFront:nil]; | 5619 [window makeKeyAndOrderFront:nil]; |
5577 #ifdef BUILDING_FOR_SNOW_LEOPARD | 5620 #ifdef BUILDING_FOR_SNOW_LEOPARD |
5578 [window setAllowsConcurrentViewDrawing:NO]; | 5621 [window setAllowsConcurrentViewDrawing:NO]; |
5579 #endif | 5622 #endif |
5580 [view release]; | 5623 [view release]; |
5581 | 5624 |
5582 /* If it isn't a toplevel window... */ | 5625 /* If it isn't a toplevel window... */ |
5583 if(hwndOwner) | 5626 if(hwndOwner) |
5584 { | 5627 { |
5585 id object = hwndOwner; | 5628 id object = hwndOwner; |
5586 | 5629 |
5587 /* Check to see if the parent is an MDI window */ | 5630 /* Check to see if the parent is an MDI window */ |
5588 if([object isMemberOfClass:[DWMDI class]]) | 5631 if([object isMemberOfClass:[DWMDI class]]) |
5589 { | 5632 { |
5590 /* Set the window level to be floating */ | 5633 /* Set the window level to be floating */ |
5591 [window setLevel:NSFloatingWindowLevel]; | 5634 [window setLevel:NSFloatingWindowLevel]; |
5621 * cursortype: ID of the pointer you want. | 5664 * cursortype: ID of the pointer you want. |
5622 */ | 5665 */ |
5623 void API dw_window_set_pointer(HWND handle, int pointertype) | 5666 void API dw_window_set_pointer(HWND handle, int pointertype) |
5624 { | 5667 { |
5625 id object = handle; | 5668 id object = handle; |
5626 | 5669 |
5627 if([ object isKindOfClass:[ NSView class ] ]) | 5670 if([ object isKindOfClass:[ NSView class ] ]) |
5628 { | 5671 { |
5629 NSView *view = handle; | 5672 NSView *view = handle; |
5630 | 5673 |
5631 if(pointertype == DW_POINTER_DEFAULT) | 5674 if(pointertype == DW_POINTER_DEFAULT) |
5632 { | 5675 { |
5633 [view discardCursorRects]; | 5676 [view discardCursorRects]; |
5634 } | 5677 } |
5635 else if(pointertype == DW_POINTER_ARROW) | 5678 else if(pointertype == DW_POINTER_ARROW) |
5636 { | 5679 { |
5637 NSRect rect = [view frame]; | 5680 NSRect rect = [view frame]; |
5638 NSCursor *cursor = [NSCursor arrowCursor]; | 5681 NSCursor *cursor = [NSCursor arrowCursor]; |
5639 | 5682 |
5640 [view addCursorRect:rect cursor:cursor]; | 5683 [view addCursorRect:rect cursor:cursor]; |
5641 } | 5684 } |
5642 /* No cursor for DW_POINTER_CLOCK? */ | 5685 /* No cursor for DW_POINTER_CLOCK? */ |
5643 } | 5686 } |
5644 } | 5687 } |
5671 * handle: The window handle to make visible. | 5714 * handle: The window handle to make visible. |
5672 */ | 5715 */ |
5673 int API dw_window_hide(HWND handle) | 5716 int API dw_window_hide(HWND handle) |
5674 { | 5717 { |
5675 /* TODO: Figure out proper dw_window_hide behavior... | 5718 /* TODO: Figure out proper dw_window_hide behavior... |
5676 * individual windows don't appear to be hidable, | 5719 * individual windows don't appear to be hidable, |
5677 * but all application windows can be hidden/deactivated | 5720 * but all application windows can be hidden/deactivated |
5678 * via the NS/DWApplication class. | 5721 * via the NS/DWApplication class. |
5679 */ | 5722 */ |
5680 return 0; | 5723 return 0; |
5681 } | 5724 } |
5780 * handle: Handle to receive mouse input. | 5823 * handle: Handle to receive mouse input. |
5781 */ | 5824 */ |
5782 void API dw_window_capture(HWND handle) | 5825 void API dw_window_capture(HWND handle) |
5783 { | 5826 { |
5784 id object = handle; | 5827 id object = handle; |
5785 | 5828 |
5786 if(![object isMemberOfClass:[NSWindow class]]) | 5829 if(![object isMemberOfClass:[NSWindow class]]) |
5787 { | 5830 { |
5788 object = [object window]; | 5831 object = [object window]; |
5789 } | 5832 } |
5790 if(object) | 5833 if(object) |
5823 * newparent: The window's new parent window. | 5866 * newparent: The window's new parent window. |
5824 */ | 5867 */ |
5825 void API dw_window_reparent(HWND handle, HWND newparent) | 5868 void API dw_window_reparent(HWND handle, HWND newparent) |
5826 { | 5869 { |
5827 id object = handle; | 5870 id object = handle; |
5828 | 5871 |
5829 if([object isMemberOfClass:[NSWindow class]]) | 5872 if([object isMemberOfClass:[NSWindow class]]) |
5830 { | 5873 { |
5831 /* We can't actually reparent on MacOS but if the | 5874 /* We can't actually reparent on MacOS but if the |
5832 * new parent is an MDI window, change to be a | 5875 * new parent is an MDI window, change to be a |
5833 * floating window... otherwise set it to normal. | 5876 * floating window... otherwise set it to normal. |
5834 */ | 5877 */ |
5835 NSWindow *window = handle; | 5878 NSWindow *window = handle; |
5836 | 5879 |
5837 /* If it isn't a toplevel window... */ | 5880 /* If it isn't a toplevel window... */ |
5838 if(newparent) | 5881 if(newparent) |
5839 { | 5882 { |
5840 object = newparent; | 5883 object = newparent; |
5841 | 5884 |
5842 /* Check to see if the parent is an MDI window */ | 5885 /* Check to see if the parent is an MDI window */ |
5843 if([object isMemberOfClass:[DWMDI class]]) | 5886 if([object isMemberOfClass:[DWMDI class]]) |
5844 { | 5887 { |
5845 /* Set the window level to be floating */ | 5888 /* Set the window level to be floating */ |
5846 [window setLevel:NSFloatingWindowLevel]; | 5889 [window setLevel:NSFloatingWindowLevel]; |
5864 { | 5907 { |
5865 char *fontcopy = strdup(fontname); | 5908 char *fontcopy = strdup(fontname); |
5866 char *name = strchr(fontcopy, '.'); | 5909 char *name = strchr(fontcopy, '.'); |
5867 if(name) | 5910 if(name) |
5868 { | 5911 { |
5869 int size = atoi(fontcopy); | 5912 int size = atoi(fontcopy); |
5870 *name = 0; | 5913 *name = 0; |
5871 name++; | 5914 name++; |
5872 NSFont *font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size]; | 5915 NSFont *font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size]; |
5873 if(font) | 5916 if(font) |
5874 { | 5917 { |
5888 free(fontcopy); | 5931 free(fontcopy); |
5889 return 0; | 5932 return 0; |
5890 } | 5933 } |
5891 | 5934 |
5892 /* | 5935 /* |
5936 * Returns the current font for the specified window | |
5937 * Parameters: | |
5938 * handle: The window handle from which to obtain the font. | |
5939 */ | |
5940 char * API dw_window_get_font(HWND handle) | |
5941 { | |
5942 NSLog(@"dw_window_get_font() unimplemented\n"); | |
5943 return "8.Monaco"; | |
5944 } | |
5945 | |
5946 /* | |
5893 * Destroys a window and all of it's children. | 5947 * Destroys a window and all of it's children. |
5894 * Parameters: | 5948 * Parameters: |
5895 * handle: The window handle to destroy. | 5949 * handle: The window handle to destroy. |
5896 */ | 5950 */ |
5897 int API dw_window_destroy(HWND handle) | 5951 int API dw_window_destroy(HWND handle) |
6034 NSObject *object = handle; | 6088 NSObject *object = handle; |
6035 if([ object isKindOfClass:[ NSImageView class ] ]) | 6089 if([ object isKindOfClass:[ NSImageView class ] ]) |
6036 { | 6090 { |
6037 NSImageView *iv = handle; | 6091 NSImageView *iv = handle; |
6038 NSImage *bitmap = NULL; | 6092 NSImage *bitmap = NULL; |
6039 | 6093 |
6040 if(filename) | 6094 if(filename) |
6041 { | 6095 { |
6042 bitmap = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; | 6096 bitmap = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; |
6043 } | 6097 } |
6044 else if(resid > 0 && resid < 65536) | 6098 else if(resid > 0 && resid < 65536) |
6140 int _locked_by_me = FALSE; | 6194 int _locked_by_me = FALSE; |
6141 DW_MUTEX_LOCK; | 6195 DW_MUTEX_LOCK; |
6142 NSObject *object = handle; | 6196 NSObject *object = handle; |
6143 NSSize size; | 6197 NSSize size; |
6144 size.width = width; | 6198 size.width = width; |
6145 size.height = height; | 6199 size.height = height; |
6146 | 6200 |
6147 if([ object isKindOfClass:[ NSWindow class ] ]) | 6201 if([ object isKindOfClass:[ NSWindow class ] ]) |
6148 { | 6202 { |
6149 NSWindow *window = handle; | 6203 NSWindow *window = handle; |
6150 [window setContentSize:size]; | 6204 [window setContentSize:size]; |
6164 int _locked_by_me = FALSE; | 6218 int _locked_by_me = FALSE; |
6165 DW_MUTEX_LOCK; | 6219 DW_MUTEX_LOCK; |
6166 NSObject *object = handle; | 6220 NSObject *object = handle; |
6167 NSPoint point; | 6221 NSPoint point; |
6168 point.x = x; | 6222 point.x = x; |
6169 point.y = y; | 6223 point.y = y; |
6170 | 6224 |
6171 if([ object isKindOfClass:[ NSWindow class ] ]) | 6225 if([ object isKindOfClass:[ NSWindow class ] ]) |
6172 { | 6226 { |
6173 NSWindow *window = handle; | 6227 NSWindow *window = handle; |
6174 [window setFrameOrigin:point]; | 6228 [window setFrameOrigin:point]; |
6214 *y = rect.origin.y; | 6268 *y = rect.origin.y; |
6215 if(width) | 6269 if(width) |
6216 *width = rect.size.width; | 6270 *width = rect.size.width; |
6217 if(height) | 6271 if(height) |
6218 *height = rect.size.height; | 6272 *height = rect.size.height; |
6219 return; | 6273 return; |
6220 } | 6274 } |
6221 } | 6275 } |
6222 | 6276 |
6223 /* | 6277 /* |
6224 * Returns the width of the screen. | 6278 * Returns the width of the screen. |
6225 */ | 6279 */ |
6226 int API dw_screen_width(void) | 6280 int API dw_screen_width(void) |
6227 { | 6281 { |
6228 NSRect screenRect = [[NSScreen mainScreen] frame]; | 6282 NSRect screenRect = [[NSScreen mainScreen] frame]; |
6229 return screenRect.size.width; | 6283 return screenRect.size.width; |
6230 } | 6284 } |
6231 | 6285 |
6232 /* | 6286 /* |
6233 * Returns the height of the screen. | 6287 * Returns the height of the screen. |
6234 */ | 6288 */ |
6235 int API dw_screen_height(void) | 6289 int API dw_screen_height(void) |
6236 { | 6290 { |
6237 NSRect screenRect = [[NSScreen mainScreen] frame]; | 6291 NSRect screenRect = [[NSScreen mainScreen] frame]; |
6238 return screenRect.size.height; | 6292 return screenRect.size.height; |
6239 } | 6293 } |
6240 | 6294 |
6241 /* This should return the current color depth */ | 6295 /* This should return the current color depth */ |
6242 unsigned long API dw_color_depth_get(void) | 6296 unsigned long API dw_color_depth_get(void) |
6569 * data: User data to be passed to the handler function. | 6623 * data: User data to be passed to the handler function. |
6570 */ | 6624 */ |
6571 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) | 6625 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) |
6572 { | 6626 { |
6573 ULONG message = 0, msgid = 0; | 6627 ULONG message = 0, msgid = 0; |
6574 | 6628 |
6575 if(window && signame && sigfunc) | 6629 if(window && signame && sigfunc) |
6576 { | 6630 { |
6577 if((message = _findsigmessage(signame)) != 0) | 6631 if((message = _findsigmessage(signame)) != 0) |
6578 { | 6632 { |
6579 _new_signal(message, window, (int)msgid, sigfunc, data); | 6633 _new_signal(message, window, (int)msgid, sigfunc, data); |
6802 * mutex: The handle to the mutex returned by dw_mutex_new(). | 6856 * mutex: The handle to the mutex returned by dw_mutex_new(). |
6803 */ | 6857 */ |
6804 void dw_mutex_lock(HMTX mutex) | 6858 void dw_mutex_lock(HMTX mutex) |
6805 { | 6859 { |
6806 /* We need to handle locks from the main thread differently... | 6860 /* We need to handle locks from the main thread differently... |
6807 * since we can't stop message processing... otherwise we | 6861 * since we can't stop message processing... otherwise we |
6808 * will deadlock... so try to acquire the lock and continue | 6862 * will deadlock... so try to acquire the lock and continue |
6809 * processing messages in between tries. | 6863 * processing messages in between tries. |
6810 */ | 6864 */ |
6811 if(DWThread == pthread_self()) | 6865 if(DWThread == pthread_self()) |
6812 { | 6866 { |
7315 #if !defined(GARBAGE_COLLECT) | 7369 #if !defined(GARBAGE_COLLECT) |
7316 NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key); | 7370 NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key); |
7317 [pool drain]; | 7371 [pool drain]; |
7318 pool = [[NSAutoreleasePool alloc] init]; | 7372 pool = [[NSAutoreleasePool alloc] init]; |
7319 pthread_setspecific(_dw_pool_key, pool); | 7373 pthread_setspecific(_dw_pool_key, pool); |
7320 #endif | 7374 #endif |
7321 } | 7375 } |
7322 | 7376 |
7323 /* | 7377 /* |
7324 * Setup thread independent pools. | 7378 * Setup thread independent pools. |
7325 */ | 7379 */ |