Add a bunch of new NSView classes (to form a meta-view BSSourceView) that adds a...
[macgdbp.git] / Source / BSSourceView.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2008, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "BSSourceView.h"
18
19 @interface BSSourceView (Private)
20 - (void)setupViews;
21 @end
22
23 @implementation BSSourceView
24
25 @synthesize numberView, textView, scrollView;
26
27 /**
28 * Initializes the source view with the path of a file
29 */
30 - (id)initWithFrame:(NSRect)frame
31 {
32 if (self = [super initWithFrame:frame])
33 {
34 [self setupViews];
35 }
36 return self;
37 }
38
39 /**
40 * Flip the coordinates
41 */
42 - (BOOL)isFlipped
43 {
44 return YES;
45 }
46
47 /**
48 * Setup all the subviews for the source metaview
49 */
50 - (void)setupViews
51 {
52 int gutterWidth = 30;
53
54 // setup the line number view
55 NSRect numberFrame = [self bounds];
56 numberFrame.origin = NSMakePoint(0.0, 0.0);
57 numberFrame.size.width = gutterWidth;
58 numberView = [[BSLineNumberView alloc] initWithFrame:numberFrame];
59 [numberView setAutoresizingMask:NSViewHeightSizable];
60 [numberView setSourceView:self];
61 [self addSubview:numberView];
62
63 // create the scroll view
64 NSRect scrollFrame = [self bounds];
65 scrollFrame.origin.x = gutterWidth;
66 scrollFrame.size.width = scrollFrame.size.width - gutterWidth;
67 scrollView = [[NSScrollView alloc] initWithFrame:scrollFrame];
68 [scrollView setHasHorizontalScroller:YES];
69 [scrollView setHasVerticalScroller:YES];
70 [scrollView setBorderType:NSBezelBorder];
71 [scrollView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
72 [[scrollView contentView] setAutoresizesSubviews:YES];
73 [self addSubview:scrollView];
74
75 // add the text view to the scroll view
76 NSRect textFrame;
77 textFrame.origin = NSMakePoint(0.0, 0.0);
78 textFrame.size = [scrollView contentSize];
79 textView = [[BSSourceViewTextView alloc] initWithFrame:textFrame];
80 [textView setSourceView:self];
81 [textView setEditable:NO];
82 [textView setFont:[NSFont fontWithName:@"Monaco" size:10.0]];
83 [textView setHorizontallyResizable:YES];
84 [textView setVerticallyResizable:YES];
85 [textView setMinSize:textFrame.size];
86 [textView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
87 [[textView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
88 [[textView textContainer] setWidthTracksTextView:NO];
89 [[textView textContainer] setHeightTracksTextView:NO];
90 [textView setAutoresizingMask:NSViewNotSizable];
91 [scrollView setDocumentView:textView];
92 }
93
94 @end