[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSTabView Fix
From: |
Fred Kiefer |
Subject: |
Re: NSTabView Fix |
Date: |
Tue, 27 Feb 2007 11:49:51 +0100 |
User-agent: |
Thunderbird 1.5.0.9 (X11/20060911) |
Wolfgang Lux schrieb:
> Andreas Höschler wrote:
>
>>
>>>>> and we need to make sure these two match in some way. And what I
>>>>> tried to do was just this. If I failed on doing so, please show me
>>>>> my > wrongs.
>>>>
>>>> Create a tabView and add four tabViewItems. _selected_item will be
>>>> 4. Then call selectedTabViewItem! Boohm!!!
>>>
>>> So what? Fred's change looked okay to me (and still looks so). The
>>> point is
>>> just that NSTabView fails to initialize the _selected_item instance
>>> variable
>>> properly. Adding the line
>>> _selected_item = NSNotFound;
>>> in -initWithFrame: should fix this issue.
>>
>> If NSNotFound is and will stay defined as -1 then YES! Can we build on
>> that?
>
> No, because 0x7fffffff != -1 :-) (see NSObject.h; it's the same on
> Cocoa). Anyway
> there is really no need to do so because the code (with two exceptions,
> see below)
> carefully checks whether _selected_item is NSNotFound before
> incrementing or
> decrementing the instance variable.
>
> The two methods were the check is absent are -selectNextTabViewItem: and
> -selectPreviousTabViewItem:. These methods might be changed as follows
>
> - (void) selectNextTabViewItem: (id)sender
> {
> #if 0
> /* the check below does work because 0x80000000 is cast to unsigned
> and thus
> * greater than the number of items; nevertheless, checking
> explicitly for
> * NSNotFound improves code clarity */
> if ((unsigned)(_selected_item + 1) < [_items count])
> #endif
> if (_selected_item != NSNotFound && (unsigned)(_selected_item + 1) <
> [_items count]))
> [self selectTabViewItemAtIndex: _selected_item+1];
> }
>
> - (void) selectPreviousTabViewItem: (id)sender
> {
> #if 0
> /* the check below works just because even NSNotFound-1 is greater
> than the
> index of any item in the tab view and therefore
> selectTabViewItemAtIndex:
> will set the selected item (redundantly) to nil (and thereby also
> _selected_item to NSNotFound); nevertheless, checking explicitly for
> NSNotFound improves code clarity. */
> if (_selected_item > 0)
> #endif
> if (_selected_item != NSNotFound && _selected_item > 0)
> [self selectTabViewItemAtIndex: _selected_item-1];
> }
>
>
>> Sorry (to Fred), I haven't looked for a fix for the fix yesterday. I
>> just discovered that the modification broke my code and therefore
>> rolled back to the older implementation. I suppose _selected_item =
>> -1; in the init method will do the trick.
>
> No, it won't. You have to use _selected_item = NSNotFound or you are
> going to
> break other things in NSTabView.m.
>
Thank you for this patch. It is now in SVN.
Cheers,
Fred