1/*
2**  PlopWindow.m
3**
4**  Copyright (c) 2002
5**
6**  Author: Ludovic Marcotte <ludovic@Sophos.ca>
7**
8**  This program is free software; you can redistribute it and/or modify
9**  it under the terms of the GNU General Public License as published by
10**  the Free Software Foundation; either version 2 of the License, or
11**  (at your option) any later version.
12**
13**  This program is distributed in the hope that it will be useful,
14**  but WITHOUT ANY WARRANTY; without even the implied warranty of
15**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16**  GNU General Public License for more details.
17**
18**  You should have received a copy of the GNU General Public License
19**  along with this program; if not, write to the Free Software
20**  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23#import "PlopWindow.h"
24
25#import "Constants.h"
26#import "PlopView.h"
27
28@implementation PlopWindow
29
30
31//
32//
33//
34- (id) initWithContentRect: (NSRect) contentRect
35		 styleMask: (unsigned int) styleMask
36		   backing: (NSBackingStoreType) backingType
37		     defer: (BOOL) flag
38{
39  self = [super initWithContentRect: contentRect
40		styleMask: styleMask
41		backing: backingType
42		defer: flag];
43
44  [self setPreviousSize: NSMakeSize(DEFAULT_PLOP_WIDTH, DEFAULT_PLOP_HEIGHT)];
45
46  return self;
47}
48
49//
50//
51//
52- (void) dealloc
53{
54  //NSLog(@"PlopWindow: -dealloc");
55  RELEASE(plopView);
56
57  RELEASE(textView);
58  RELEASE(scrollView);
59
60  [super dealloc];
61}
62
63
64//
65//
66//
67- (void) layoutWindow
68{
69  plopView = [[PlopView alloc] init];
70  [plopView setFrame: NSMakeRect(0,0,DEFAULT_PLOP_WIDTH,DEFAULT_PLOP_HEIGHT)];
71  [plopView setAutoresizingMask: (NSViewWidthSizable|NSViewHeightSizable)];
72  [plopView setWindow: self];
73
74  scrollView = [[NSScrollView alloc] initWithFrame: NSMakeRect(30,14,DEFAULT_PLOP_WIDTH-6,DEFAULT_PLOP_HEIGHT - 25)];
75
76  textView = [[NSTextView alloc] initWithFrame: [[scrollView contentView] frame]];
77  //[textView setTextContainerInset: NSMakeSize(5,5)];
78  [textView setBackgroundColor: [NSColor whiteColor]];
79  [textView setDrawsBackground: YES];
80  [textView setRichText: YES];
81  [textView setUsesFontPanel: YES];
82  [textView setHorizontallyResizable: NO];
83  [textView setVerticallyResizable: YES];
84  [textView setMinSize: NSMakeSize (0, 0)];
85  [textView setMaxSize: NSMakeSize (1E7, 1E7)];
86  [textView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
87  [[textView textContainer] setContainerSize: NSMakeSize([[scrollView contentView] frame].size.width,
88  							 1E7)];
89  [[textView textContainer] setWidthTracksTextView: YES];
90  [textView setEditable: NO];
91  [textView setDelegate: [self windowController]];
92
93  [scrollView setDocumentView: textView];
94  [scrollView setHasHorizontalScroller: NO];
95  [scrollView setHasVerticalScroller: NO];
96  [scrollView setBorderType: NSNoBorder];
97  [scrollView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
98
99  [[self contentView] addSubview: plopView];
100  [[self contentView] addSubview: scrollView];
101}
102
103
104//
105//
106//
107- (BOOL) canBecomeKeyWindow
108{
109  return YES;
110}
111
112
113//
114// access/mutation methods
115//
116- (NSSize) maxSize
117{
118  NSRect aRect;
119
120  aRect = [[NSScreen mainScreen] frame];
121
122  return NSMakeSize(aRect.size.width - 140, aRect.size.height - 140);
123}
124
125- (NSSize) minSize
126{
127  return NSMakeSize(36,40);
128}
129
130
131- (NSSize) previousSize
132{
133  return previousSize;
134}
135
136- (void) setPreviousSize: (NSSize) theSize
137{
138  previousSize = theSize;
139}
140
141
142- (PlopView *) plopView
143{
144  return plopView;
145}
146
147
148- (NSTextView *) textView
149{
150  return textView;
151}
152
153@end
154