/* ** NoteTextView.m ** ** Copyright (c) 2004 ** ** Author: Yen-Ju Chen ** ** 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 "NoteTextView.h" #include "Constants.h" @protocol GraphicComponentInfo - (int) tag; @end @implementation NoteTextView /* methods */ - (BOOL) isNoteTextViewEditable { return noteTextViewEditable; } - (void) setNoteTextViewEditable: (BOOL) editable { if (editable) { unsigned int length = [[self string] length]; NSRange allRange = NSMakeRange(0, length); [self setBackgroundColor: [NSColor yellowColor]]; [self setEditable: YES]; [self setRichText: NO]; /* Reset font attributes */ if (length) [[self textStorage] setAttributes: fontAttributes range: allRange]; noteTextViewEditable = YES; } else { [self setBackgroundColor: [NSColor whiteColor]]; [self setEditable: NO]; [self setRichText: YES]; noteTextViewEditable = NO; } } /* Override */ - (BOOL) performDragOperation: (id ) sender { if ([[sender draggingSource] respondsToSelector: @selector(tag)]) { int tvTag = [(id )[sender draggingSource] tag]; NSPasteboard *pboard = [sender draggingPasteboard]; if ((ItemTableViewTag == tvTag) || (SourceTableViewTag == tvTag)) { /* Try to change the content of pasteboard */ if ([[pboard types] containsObject: NSStringPboardType]) { NSString *title = [pboard stringForType: NSStringPboardType]; [pboard setString: [NSString stringWithFormat: @"%@", title] forType: NSStringPboardType]; } } } return [super performDragOperation: sender]; } - (int) tag { return tag; } - (void) setTag: (int) anInt { tag = anInt; } - (id) init { self = [super init]; tag = 0; noteTextViewEditable = YES; /* Get default font attributes */ ASSIGN(fontAttributes, AUTORELEASE([[[self textStorage] fontAttributesInRange: NSMakeRange(0, 0)] copy])); return self; } @end