File: LogWindowController.m

package info (click to toggle)
lusernet.app 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 828 kB
  • sloc: objc: 8,495; makefile: 22
file content (93 lines) | stat: -rw-r--r-- 2,171 bytes parent folder | download | duplicates (6)
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
/*
copyright 2002 Alexander Malmberg <alexander@malmberg.org>
*/

#include <Foundation/NSObject.h>
#include <Foundation/NSBundle.h>
#include <AppKit/NSWindow.h>
#include <AppKit/NSScrollView.h>
#include <AppKit/NSTextView.h>
#include <AppKit/NSTextContainer.h>
#include <AppKit/NSTextStorage.h>
#include <AppKit/NSClipView.h>

#include "LogWindowController.h"


@implementation LogWindowController

- init
{
	NSWindow *win;

	win=[[NSWindow alloc] initWithContentRect: NSMakeRect(100,100,500,200)
		styleMask: NSClosableWindowMask|NSTitledWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask
		backing: NSBackingStoreRetained
		defer: YES];
	if (!(self=[super initWithWindow: win])) return nil;

	{ /* TODO: fix properly */
		NSScrollView *sv;
//		NSRect r;

//		r=NSMakeRect(0,0,500,200);

		[win setTitle: _(@"Log")];

//		sv=[[NSScrollView alloc] initWithFrame: r];
		sv=[[NSScrollView alloc] init];
//		[sv setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
//		[sv setAutoresizesSubviews: YES];
		[sv setHasVerticalScroller: YES];
		[sv setHasHorizontalScroller: NO];
		[sv setBorderType: NSBezelBorder];

		log=[[NSTextView alloc] initWithFrame: [[sv contentView] frame]];
//		log=[[NSTextView alloc] init];
		[log setHorizontallyResizable: NO];
		[log setVerticallyResizable: YES];
		[log setEditable: NO];
		[[log textContainer] setWidthTracksTextView: YES];
		[[log textContainer] setHeightTracksTextView: NO];
		[[log textContainer] setContainerSize: NSMakeSize(0,1e6)];
		[log setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];

		[sv setDocumentView: log];

		[win setContentView: sv];

		[sv release];
	}

	[win setFrameUsingName: @"LogWindow"];
	[win setFrameAutosaveName: @"LogWindow"];

	[win release];

	return self;
}

-(void) dealloc
{
	DESTROY(log);
	[super dealloc];
}


-(void) addLogString: (NSString *)s
{
	NSTextStorage *ts;
	int l;

	ts=[log textStorage];
	[ts beginEditing];
	l=[ts length];
	[ts replaceCharactersInRange: NSMakeRange(l,0) withString: s];
	l+=[s length];
	[ts replaceCharactersInRange: NSMakeRange(l,0) withString: @"\n"];
	[ts endEditing];
	[log scrollRangeToVisible: NSMakeRange(l-1,1)];
}

@end