File: MyImageListWindowOutlineView.m

package info (click to toggle)
lynkeos.app 3.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,832 kB
  • sloc: objc: 41,053; ansic: 812; cpp: 151; sh: 68; makefile: 27
file content (269 lines) | stat: -rw-r--r-- 8,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//
//  Lynkeos
//  $Id$
//
//  Created by Jean-Etienne LAMIAUD on Tue May 22 2007.
//  Copyright (c) 2007-2025. Jean-Etienne LAMIAUD
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//

#include "MyDocument.h"
#include "MyImageListWindow.h"

@implementation MyImageListWindow(Outline)

// User select or deselect a line
- (BOOL) outlineView:(NSOutlineView*)outlineView shouldSelectItem:(id)item
{
   return ( _itemSelectionAuthorized && _dataMode == ListData );
}

- (void) outlineViewSelectionDidChange :(NSNotification*)aNotification
{
   NSInteger row = [_textView selectedRow];

   _highlightedItem = nil;

   if ( row != -1 && _dataMode == ListData )
      // Selection is valid
      _highlightedItem = [_textView itemAtRow:row];

   // Notify to clients
   [[NSNotificationCenter defaultCenter] postNotificationName:
                                                   LynkeosHilightedItemDidChangeNotification
                                                       object:self];
}

- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell
     forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
   [cell setEditable: (_itemEditionAuthorized && _dataMode == ListData)];

   // Notify, to permit a custom redraw by processing views 
   NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                         outlineView, LynkeosOutlineView,
                         cell,        LynkeosOutlineViewCell,
                         tableColumn, LynkeosOutlineViewColumn,
                         item,        LynkeosOutlineViewItem,
                         nil];
   [[NSNotificationCenter defaultCenter] postNotificationName:
                                   LynkeosOutlineViewWillDisplayCellNotification
                                                       object:self
                                                     userInfo:dict];
}

- (id) outlineView:(NSOutlineView *)outlineView child:(NSInteger)index
            ofItem:(id)item
{
   if ( _dataMode == ListData )
   {
      if (_outlineDisplay)
      {
         if ( item == nil )
            return( [[_currentList imageArray] objectAtIndex: index] );

         else
            return( [item getChildAtIndex:index] );
      }
      else
      {
         NSAssert( item == nil, @"Sorted display has no hierarchy" );
         NSAssert(_sortedItems != nil, @"Sorted display lacks the sorted array");
         return [_sortedItems objectAtIndex:index];
      }
   }
   else
   {
      NSAssert( item == nil && index == 0, @"Result has no children" );
      return( _currentList );
   }
}

- (BOOL) outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
   if ( _dataMode == ListData )
   {
      if (_outlineDisplay)
         return ( [item numberOfChildren] != 0 );
      else
         return NO;
   }
   else
      return( NO );
}

- (NSInteger) outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
   if ( _dataMode == ListData )
   {
      if (_outlineDisplay)
      {
         if ( item == nil )
            return( [[_currentList imageArray] count] );
         else
            return( [item numberOfChildren] );
      }
      else
      {
         if ( item == nil )
            return( [_sortedItems count] );
         else
            return 0;
      }
   }
   else
   {
      NSAssert( item == nil, @"Result has no chidren" );
      double b, w, g;

      if ( [_currentList getBlackLevel:&b whiteLevel:&w gamma:&g] )
         return(1);
      else
         return(0);
   }
}

- (id) outlineView:(NSOutlineView *)outlineView 
       objectValueForTableColumn:(NSTableColumn *)tableColumn
            byItem:(id)item
{
   id columnId = [tableColumn identifier];

   // Find this column description
   LynkeosColumnDescription *desc = [_columnsDescriptor objectForKey:columnId];
   if ( desc != nil )
   {
      // Get the parameter to display
      NSObject <LynkeosProcessingParameter> *param =
                   [item getProcessingParameterWithRef:desc->_parameterReference
                                         forProcessing:desc->_processingRef];
      if ( param != nil )
      {
         // Get the field
         NSValue *field = [param valueForKey:desc->_fieldName];
         if ( field != nil )
         {
            if ( desc->_format != nil )
            {
#define FormatStr(t) \
   { t v; [field getValue:&v]; \
     cellStr = [NSString stringWithFormat:desc->_format, v]; break; }
               const char *fieldType = [field objCType];
               NSString *cellStr = nil;

               NSAssert1( strlen(fieldType) == 1,
                          @"Unsupported field type : %s", fieldType );

               switch( *fieldType )
               {
                  case 'c' :
                  case 'C' : FormatStr(char)
                  case 's' :
                  case 'S' : FormatStr(short)
                  case 'i' :
                  case 'I' : FormatStr(int)
                  case 'l' :
                  case 'L' : FormatStr(long)
                  case 'q' :
                  case 'Q' : FormatStr(long long)
                  case 'f' : FormatStr(float)
                  case 'd' : FormatStr(double)
                  case 'B' : FormatStr(BOOL)
                  case '*' : FormatStr(char*)
                  default :
                     NSLog( @"Unsupported field type %s", fieldType );
                     break;
               }
               return( cellStr );
            }
            else
               return( field );
         }
      }
   }

   return( nil );
}

- (void)outlineView:(NSOutlineView *)outlineView
     setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn 
             byItem:(id)item
{
   if ( [[tableColumn identifier] isEqual:@"select"] )
   {
      MyDocument *doc = [self document];
      [doc changeEntrySelection :item value :[object boolValue]];

      // Redraw other affected lines
      if ( [item numberOfChildren] != 0 )
         [_textView reloadItem:item reloadChildren:YES];
      else
      {
         MyImageListItem *parent = [item getParent];

         if ( parent != nil )
            [_textView reloadItem:parent reloadChildren:NO];
      }
   }
}

- (void) outlineView:(NSOutlineView *) outlineView
 didClickTableColumn:(NSTableColumn *) tableColumn
{
   if ( _dataMode == ListData )
   {
      NSUserInterfaceItemIdentifier columnId = [tableColumn identifier];

      // Remove the sort mark on the previously sorted column
      NSTableColumn *sortedCol = [outlineView tableColumnWithIdentifier:_sortColumn];
      if (sortedCol != nil &&
          ([sortedCol.title hasSuffix:@"↓"] || [sortedCol.title hasSuffix:@"↑"]))
      {
         NSString *colTitle = [sortedCol.title substringToIndex:[sortedCol.title length] - 1];
         sortedCol.title = colTitle;
      }
      
      // Set the display mode according to the clicked column
      if ( [columnId isEqual:@"select"] )
      {
         _outlineDisplay = YES;
         if (_sortedItems != nil)
         {
            [_sortedItems release];
            _sortedItems = nil;
         }
      }
      else
      {
         _outlineDisplay = NO;
         if (_sortColumn != columnId)
            // Initial sort direction
            _sortUp = ![columnId isEqual:@"quality"];
         else
            // Reverse the sort direction
            _sortUp = !_sortUp;
         _sortColumn = columnId;

         // Display a sort indicator
         tableColumn.title = [tableColumn.title stringByAppendingString:(_sortUp ? @"↓" : @"↑")];
//         NSSortDescriptor *desc = [NSSortDescriptor sortDescriptorWithKey:tableColumn.title
//                                                                ascending:_sortUp];
//         [tableColumn setSortDescriptorPrototype: desc];
      }
      [self reloadData];
   }
}
@end