Mercurial > dwindows
comparison mac/dw.m @ 1543:b86a04751ea0
Refactor MLE code on Mac to be more like the Container and Tree code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 13 Jan 2012 03:29:23 +0000 |
parents | 333f07bdbf7c |
children | ca6be9c48fff |
comparison
equal
deleted
inserted
replaced
1542:edbc7405ed4d | 1543:b86a04751ea0 |
---|---|
1435 | 1435 |
1436 /* Subclass for a MLE type */ | 1436 /* Subclass for a MLE type */ |
1437 @interface DWMLE : NSTextView | 1437 @interface DWMLE : NSTextView |
1438 { | 1438 { |
1439 void *userdata; | 1439 void *userdata; |
1440 id scrollview; | |
1440 } | 1441 } |
1441 -(void *)userdata; | 1442 -(void *)userdata; |
1442 -(void)setUserdata:(void *)input; | 1443 -(void)setUserdata:(void *)input; |
1444 -(id)scrollview; | |
1445 -(void)setScrollview:(id)input; | |
1443 @end | 1446 @end |
1444 | 1447 |
1445 @implementation DWMLE | 1448 @implementation DWMLE |
1446 -(void *)userdata { return userdata; } | 1449 -(void *)userdata { return userdata; } |
1447 -(void)setUserdata:(void *)input { userdata = input; } | 1450 -(void)setUserdata:(void *)input { userdata = input; } |
1451 -(id)scrollview { return scrollview; } | |
1452 -(void)setScrollview:(id)input { scrollview = input; } | |
1448 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } | 1453 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } |
1449 @end | 1454 @end |
1450 | 1455 |
1451 /* Subclass NSTextFieldCell for displaying image and text */ | 1456 /* Subclass NSTextFieldCell for displaying image and text */ |
1452 @interface DWImageAndTextCell : NSTextFieldCell | 1457 @interface DWImageAndTextCell : NSTextFieldCell |
3526 thiswidth = size.width; | 3531 thiswidth = size.width; |
3527 thisheight = size.height; | 3532 thisheight = size.height; |
3528 } | 3533 } |
3529 } | 3534 } |
3530 /* MLE, Container and Tree */ | 3535 /* MLE, Container and Tree */ |
3531 else if([ object isMemberOfClass:[NSScrollView class] ] || | 3536 else if([ object isMemberOfClass:[DWMLE class] ] || |
3532 [ object isMemberOfClass:[DWContainer class] ] || | 3537 [ object isMemberOfClass:[DWContainer class] ] || |
3533 [ object isMemberOfClass:[DWTree class] ]) | 3538 [ object isMemberOfClass:[DWTree class] ]) |
3534 { | 3539 { |
3535 thiswidth = 500; | 3540 thiswidth = _DW_SCROLLED_MAX_WIDTH; |
3536 thisheight = 200; | 3541 thisheight = _DW_SCROLLED_MAX_HEIGHT; |
3537 } | 3542 } |
3538 /* Any other control type */ | 3543 /* Any other control type */ |
3539 else if([ object isKindOfClass:[ NSControl class ] ]) | 3544 else if([ object isKindOfClass:[ NSControl class ] ]) |
3540 nsstr = [object stringValue]; | 3545 nsstr = [object stringValue]; |
3541 | 3546 |
3599 thisbox = [view box]; | 3604 thisbox = [view box]; |
3600 thisitem = thisbox->items; | 3605 thisitem = thisbox->items; |
3601 object = item; | 3606 object = item; |
3602 | 3607 |
3603 /* Query the objects */ | 3608 /* Query the objects */ |
3604 if([ object isKindOfClass:[ DWContainer class ] ]) | 3609 if([ object isMemberOfClass:[ DWContainer class ] ] || |
3605 { | 3610 [ object isMemberOfClass:[ DWTree class ] ] || |
3606 DWContainer *cont = item; | 3611 [ object isMemberOfClass:[ DWMLE class ] ]) |
3607 this = item = [cont scrollview]; | 3612 { |
3608 } | 3613 this = item = [object scrollview]; |
3609 else if([ object isKindOfClass:[ DWTree class ] ]) | |
3610 { | |
3611 DWTree *tree = item; | |
3612 this = item = [tree scrollview]; | |
3613 } | 3614 } |
3614 | 3615 |
3615 /* Do some sanity bounds checking */ | 3616 /* Do some sanity bounds checking */ |
3616 if(index < 0) | 3617 if(index < 0) |
3617 index = 0; | 3618 index = 0; |
4665 [scrollview setHasVerticalScroller:YES]; | 4666 [scrollview setHasVerticalScroller:YES]; |
4666 [scrollview setAutohidesScrollers:YES]; | 4667 [scrollview setAutohidesScrollers:YES]; |
4667 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; | 4668 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; |
4668 [scrollview setDocumentView:mle]; | 4669 [scrollview setDocumentView:mle]; |
4669 [mle setAutoresizingMask:NSViewWidthSizable]; | 4670 [mle setAutoresizingMask:NSViewWidthSizable]; |
4671 [mle setScrollview:scrollview]; | |
4670 /* [mle setTag:cid]; Why doesn't this work? */ | 4672 /* [mle setTag:cid]; Why doesn't this work? */ |
4671 [mle autorelease]; | 4673 [mle autorelease]; |
4672 return scrollview; | 4674 return mle; |
4673 } | 4675 } |
4674 | 4676 |
4675 /* | 4677 /* |
4676 * Adds text to an MLE box and returns the current point. | 4678 * Adds text to an MLE box and returns the current point. |
4677 * Parameters: | 4679 * Parameters: |
4679 * buffer: Text buffer to be imported. | 4681 * buffer: Text buffer to be imported. |
4680 * startpoint: Point to start entering text. | 4682 * startpoint: Point to start entering text. |
4681 */ | 4683 */ |
4682 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint) | 4684 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint) |
4683 { | 4685 { |
4684 NSScrollView *sv = handle; | 4686 DWMLE *mle = handle; |
4685 int _locked_by_me = FALSE; | 4687 int _locked_by_me = FALSE; |
4686 DW_MUTEX_LOCK; | 4688 DW_MUTEX_LOCK; |
4687 DWMLE *mle = [sv documentView]; | |
4688 NSTextStorage *ts = [mle textStorage]; | 4689 NSTextStorage *ts = [mle textStorage]; |
4689 NSString *nstr = [NSString stringWithUTF8String:buffer]; | 4690 NSString *nstr = [NSString stringWithUTF8String:buffer]; |
4690 NSMutableString *ms = [ts mutableString]; | 4691 NSMutableString *ms = [ts mutableString]; |
4691 NSUInteger length = [ms length]; | 4692 NSUInteger length = [ms length]; |
4692 if(startpoint < 0) | 4693 if(startpoint < 0) |
4706 * startpoint: Point to start grabbing text. | 4707 * startpoint: Point to start grabbing text. |
4707 * length: Amount of text to be grabbed. | 4708 * length: Amount of text to be grabbed. |
4708 */ | 4709 */ |
4709 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) | 4710 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) |
4710 { | 4711 { |
4711 NSScrollView *sv = handle; | 4712 DWMLE *mle = handle; |
4712 int _locked_by_me = FALSE; | 4713 int _locked_by_me = FALSE; |
4713 DW_MUTEX_LOCK; | 4714 DW_MUTEX_LOCK; |
4714 DWMLE *mle = [sv documentView]; | |
4715 NSTextStorage *ts = [mle textStorage]; | 4715 NSTextStorage *ts = [mle textStorage]; |
4716 NSMutableString *ms = [ts mutableString]; | 4716 NSMutableString *ms = [ts mutableString]; |
4717 const char *tmp = [ms UTF8String]; | 4717 const char *tmp = [ms UTF8String]; |
4718 strncpy(buffer, tmp+startpoint, length); | 4718 strncpy(buffer, tmp+startpoint, length); |
4719 buffer[length] = '\0'; | 4719 buffer[length] = '\0'; |
4727 * bytes: A pointer to a variable to return the total bytes. | 4727 * bytes: A pointer to a variable to return the total bytes. |
4728 * lines: A pointer to a variable to return the number of lines. | 4728 * lines: A pointer to a variable to return the number of lines. |
4729 */ | 4729 */ |
4730 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines) | 4730 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines) |
4731 { | 4731 { |
4732 NSScrollView *sv = handle; | 4732 DWMLE *mle = handle; |
4733 int _locked_by_me = FALSE; | 4733 int _locked_by_me = FALSE; |
4734 DW_MUTEX_LOCK; | 4734 DW_MUTEX_LOCK; |
4735 DWMLE *mle = [sv documentView]; | |
4736 NSTextStorage *ts = [mle textStorage]; | 4735 NSTextStorage *ts = [mle textStorage]; |
4737 NSMutableString *ms = [ts mutableString]; | 4736 NSMutableString *ms = [ts mutableString]; |
4738 NSUInteger numberOfLines, index, stringLength = [ms length]; | 4737 NSUInteger numberOfLines, index, stringLength = [ms length]; |
4739 | 4738 |
4740 if(bytes) | 4739 if(bytes) |
4756 * startpoint: Point to start deleting text. | 4755 * startpoint: Point to start deleting text. |
4757 * length: Amount of text to be deleted. | 4756 * length: Amount of text to be deleted. |
4758 */ | 4757 */ |
4759 void API dw_mle_delete(HWND handle, int startpoint, int length) | 4758 void API dw_mle_delete(HWND handle, int startpoint, int length) |
4760 { | 4759 { |
4761 NSScrollView *sv = handle; | 4760 DWMLE *mle = handle; |
4762 int _locked_by_me = FALSE; | 4761 int _locked_by_me = FALSE; |
4763 DW_MUTEX_LOCK; | 4762 DW_MUTEX_LOCK; |
4764 DWMLE *mle = [sv documentView]; | |
4765 NSTextStorage *ts = [mle textStorage]; | 4763 NSTextStorage *ts = [mle textStorage]; |
4766 NSMutableString *ms = [ts mutableString]; | 4764 NSMutableString *ms = [ts mutableString]; |
4767 NSUInteger mslength = [ms length]; | 4765 NSUInteger mslength = [ms length]; |
4768 if(startpoint < 0) | 4766 if(startpoint < 0) |
4769 startpoint = 0; | 4767 startpoint = 0; |
4780 * Parameters: | 4778 * Parameters: |
4781 * handle: Handle to the MLE to be cleared. | 4779 * handle: Handle to the MLE to be cleared. |
4782 */ | 4780 */ |
4783 void API dw_mle_clear(HWND handle) | 4781 void API dw_mle_clear(HWND handle) |
4784 { | 4782 { |
4785 NSScrollView *sv = handle; | 4783 DWMLE *mle = handle; |
4786 int _locked_by_me = FALSE; | 4784 int _locked_by_me = FALSE; |
4787 DW_MUTEX_LOCK; | 4785 DW_MUTEX_LOCK; |
4788 DWMLE *mle = [sv documentView]; | |
4789 NSTextStorage *ts = [mle textStorage]; | 4786 NSTextStorage *ts = [mle textStorage]; |
4790 NSMutableString *ms = [ts mutableString]; | 4787 NSMutableString *ms = [ts mutableString]; |
4791 NSUInteger length = [ms length]; | 4788 NSUInteger length = [ms length]; |
4792 [ms deleteCharactersInRange:NSMakeRange(0, length)]; | 4789 [ms deleteCharactersInRange:NSMakeRange(0, length)]; |
4793 DW_MUTEX_UNLOCK; | 4790 DW_MUTEX_UNLOCK; |
4799 * handle: Handle to the MLE to be positioned. | 4796 * handle: Handle to the MLE to be positioned. |
4800 * line: Line to be visible. | 4797 * line: Line to be visible. |
4801 */ | 4798 */ |
4802 void API dw_mle_set_visible(HWND handle, int line) | 4799 void API dw_mle_set_visible(HWND handle, int line) |
4803 { | 4800 { |
4804 NSScrollView *sv = handle; | 4801 DWMLE *mle = handle; |
4805 int _locked_by_me = FALSE; | 4802 int _locked_by_me = FALSE; |
4806 DW_MUTEX_LOCK; | 4803 DW_MUTEX_LOCK; |
4807 DWMLE *mle = [sv documentView]; | |
4808 NSTextStorage *ts = [mle textStorage]; | 4804 NSTextStorage *ts = [mle textStorage]; |
4809 NSMutableString *ms = [ts mutableString]; | 4805 NSMutableString *ms = [ts mutableString]; |
4810 NSUInteger numberOfLines, index, stringLength = [ms length]; | 4806 NSUInteger numberOfLines, index, stringLength = [ms length]; |
4811 | 4807 |
4812 for(index=0, numberOfLines=0; index < stringLength && numberOfLines < line; numberOfLines++) | 4808 for(index=0, numberOfLines=0; index < stringLength && numberOfLines < line; numberOfLines++) |
4825 * handle: Handle to the MLE. | 4821 * handle: Handle to the MLE. |
4826 * state: TRUE if it can be edited, FALSE for readonly. | 4822 * state: TRUE if it can be edited, FALSE for readonly. |
4827 */ | 4823 */ |
4828 void API dw_mle_set_editable(HWND handle, int state) | 4824 void API dw_mle_set_editable(HWND handle, int state) |
4829 { | 4825 { |
4830 NSScrollView *sv = handle; | 4826 DWMLE *mle = handle; |
4831 DWMLE *mle = [sv documentView]; | |
4832 if(state) | 4827 if(state) |
4833 { | 4828 { |
4834 [mle setEditable:YES]; | 4829 [mle setEditable:YES]; |
4835 } | 4830 } |
4836 else | 4831 else |
4845 * handle: Handle to the MLE. | 4840 * handle: Handle to the MLE. |
4846 * state: TRUE if it wraps, FALSE if it doesn't. | 4841 * state: TRUE if it wraps, FALSE if it doesn't. |
4847 */ | 4842 */ |
4848 void API dw_mle_set_word_wrap(HWND handle, int state) | 4843 void API dw_mle_set_word_wrap(HWND handle, int state) |
4849 { | 4844 { |
4850 NSScrollView *sv = handle; | 4845 DWMLE *mle = handle; |
4851 DWMLE *mle = [sv documentView]; | |
4852 if(state) | 4846 if(state) |
4853 { | 4847 { |
4854 [mle setHorizontallyResizable:NO]; | 4848 [mle setHorizontallyResizable:NO]; |
4855 } | 4849 } |
4856 else | 4850 else |
4865 * handle: Handle to the MLE to be positioned. | 4859 * handle: Handle to the MLE to be positioned. |
4866 * point: Point to position cursor. | 4860 * point: Point to position cursor. |
4867 */ | 4861 */ |
4868 void API dw_mle_set_cursor(HWND handle, int point) | 4862 void API dw_mle_set_cursor(HWND handle, int point) |
4869 { | 4863 { |
4870 NSScrollView *sv = handle; | 4864 DWMLE *mle = handle; |
4871 int _locked_by_me = FALSE; | 4865 int _locked_by_me = FALSE; |
4872 DW_MUTEX_LOCK; | 4866 DW_MUTEX_LOCK; |
4873 DWMLE *mle = [sv documentView]; | |
4874 NSTextStorage *ts = [mle textStorage]; | 4867 NSTextStorage *ts = [mle textStorage]; |
4875 NSMutableString *ms = [ts mutableString]; | 4868 NSMutableString *ms = [ts mutableString]; |
4876 NSUInteger length = [ms length]; | 4869 NSUInteger length = [ms length]; |
4877 if(point < 0) | 4870 if(point < 0) |
4878 point = 0; | 4871 point = 0; |
4891 * point: Start point of search. | 4884 * point: Start point of search. |
4892 * flags: Search specific flags. | 4885 * flags: Search specific flags. |
4893 */ | 4886 */ |
4894 int API dw_mle_search(HWND handle, char *text, int point, unsigned long flags) | 4887 int API dw_mle_search(HWND handle, char *text, int point, unsigned long flags) |
4895 { | 4888 { |
4896 NSScrollView *sv = handle; | 4889 DWMLE *mle = handle; |
4897 int _locked_by_me = FALSE; | 4890 int _locked_by_me = FALSE; |
4898 DW_MUTEX_LOCK; | 4891 DW_MUTEX_LOCK; |
4899 DWMLE *mle = [sv documentView]; | |
4900 NSTextStorage *ts = [mle textStorage]; | 4892 NSTextStorage *ts = [mle textStorage]; |
4901 NSMutableString *ms = [ts mutableString]; | 4893 NSMutableString *ms = [ts mutableString]; |
4902 NSString *searchForMe = [NSString stringWithUTF8String:text]; | 4894 NSString *searchForMe = [NSString stringWithUTF8String:text]; |
4903 NSRange searchRange = NSMakeRange(point, [ms length] - point); | 4895 NSRange searchRange = NSMakeRange(point, [ms length] - point); |
4904 NSRange range = NSMakeRange(NSNotFound, 0); | 4896 NSRange range = NSMakeRange(NSNotFound, 0); |
7767 if(fg) | 7759 if(fg) |
7768 { | 7760 { |
7769 [cont setForegroundColor:fg]; | 7761 [cont setForegroundColor:fg]; |
7770 } | 7762 } |
7771 } | 7763 } |
7772 else if([object isKindOfClass:[NSScrollView class]]) | 7764 else if([object isMemberOfClass:[DWMLE class]]) |
7773 { | 7765 { |
7774 NSScrollView *sv = handle; | 7766 DWMLE *mle = handle; |
7775 DWMLE *mle = [sv documentView]; | |
7776 if(bg) | 7767 if(bg) |
7777 { | 7768 { |
7778 [mle setBackgroundColor:bg]; | 7769 [mle setBackgroundColor:bg]; |
7779 } | 7770 } |
7780 if(fg) | 7771 if(fg) |