OSDN Git Service

dd38d9005a5762fbb00b6f9e06e29e1a3b8e2616
[handbrake-jp/handbrake-jp-git.git] / macosx / ChapterTitles.m
1 /*  ChapterTitles.m $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.fr/>.
5    It may be used under the terms of the GNU General Public License. */
6    
7 #include "ChapterTitles.h"
8 #include "hb.h"
9
10 @implementation ChapterTitles
11 - (id)init 
12 {
13     self = [super init];
14     if( self != nil )
15     {
16         fTitle = NULL;
17     }
18     
19     return self;
20 }
21
22 - (void)resetWithTitle:(hb_title_t *)title
23 {
24     int i;
25     NSString *chapterString;
26     
27     fTitle = title;
28
29     if (!title)
30         return;
31
32     int count = hb_list_count( title->list_chapter );
33
34     for( i = 0; i < count; i++ )
35     {
36         hb_chapter_t *chapter = hb_list_item( title->list_chapter, i );
37         
38         if( chapter != NULL && chapter->title[0] == '\0' )
39         {
40             chapterString = [NSString stringWithFormat:@"Chapter %2d",(i+1)];
41     
42             strncpy( chapter->title, [chapterString UTF8String], 1023);
43             chapter->title[1023] = '\0';
44         }
45     }
46     
47 }
48
49 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
50 {
51     if( fTitle == NULL )
52     {
53         return 0;
54     }
55     else
56     {
57         return hb_list_count( fTitle->list_chapter );
58     }
59 }
60
61 - (void)tableView:(NSTableView *)aTableView
62         setObjectValue:(id)anObject
63         forTableColumn:(NSTableColumn *)aTableColumn
64         row:(int)rowIndex
65 {
66     if(aTableColumn != nil && [[aTableColumn identifier] intValue] == 2)
67     {
68         if( fTitle )
69         {
70             hb_chapter_t *chapter = hb_list_item( fTitle->list_chapter, rowIndex );
71
72             if( chapter != NULL )
73             {
74                 strncpy( chapter->title, [anObject UTF8String], 1023);
75                 chapter->title[1023] = '\0';
76             }
77         }
78     }
79 }
80
81 - (id)tableView:(NSTableView *)aTableView
82       objectValueForTableColumn:(NSTableColumn *)aTableColumn
83       row:(int)rowIndex
84 {
85     NSString *cellEntry;
86
87     if([[aTableColumn identifier] intValue] == 1)
88     {
89         cellEntry = [NSString stringWithFormat:@"%d",rowIndex+1];
90     }
91     else
92     {
93         if( fTitle )
94         {
95             hb_chapter_t *chapter = hb_list_item( fTitle->list_chapter, rowIndex );
96
97             if( chapter != NULL )
98             {
99                 cellEntry = [NSString stringWithUTF8String:chapter->title];
100             }
101         }
102         else
103         {
104                 cellEntry = @"__DATA ERROR__";
105         }
106     }
107
108     return cellEntry;
109 }
110
111 /* Method to edit the next chapter when the user presses Return. We have to use
112 a timer to avoid interfering with the chain of events that handles the edit. */
113 - (void)controlTextDidEndEditing: (NSNotification *) notification
114 {
115     NSTableView *chapterTable = [notification object];
116     NSInteger column = [chapterTable editedColumn];
117     NSInteger row = [chapterTable editedRow];
118     int textMovement;
119
120     // Edit the cell in the next row, same column
121     row++;
122     textMovement = [[[notification userInfo] objectForKey:@"NSTextMovement"] intValue];
123     if( textMovement == NSReturnTextMovement && row < [chapterTable numberOfRows] )
124     {
125         NSArray *info = [NSArray arrayWithObjects:chapterTable,
126             [NSNumber numberWithInteger:column], [NSNumber numberWithInteger:row], nil];
127         /* The delay is unimportant; editNextRow: won't be called until the responder
128         chain finishes because the event loop containing the timer is on this thread */
129         [self performSelector:@selector(editNextRow:) withObject:info afterDelay:0.0];
130     }
131 }
132
133 - (void)editNextRow: (id) objects
134 {
135     NSTableView *chapterTable = [objects objectAtIndex:0];
136     NSInteger column = [[objects objectAtIndex:1] integerValue];
137     NSInteger row = [[objects objectAtIndex:2] integerValue];
138
139     if( row >= 0 && row < [chapterTable numberOfRows] )
140     {
141         [chapterTable selectRow:row byExtendingSelection:NO];
142         [chapterTable editColumn:column row:row withEvent:nil select:YES];
143     }
144 }
145 @end