File: MQImageViewer.m

package info (click to toggle)
mysql-admin 1.2.5rc-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 80,944 kB
  • ctags: 43,103
  • sloc: sql: 295,916; pascal: 256,535; cpp: 74,487; ansic: 68,881; objc: 26,417; sh: 16,867; yacc: 10,755; java: 9,917; xml: 8,453; php: 2,806; python: 2,068; makefile: 1,252; perl: 3
file content (123 lines) | stat: -rw-r--r-- 3,012 bytes parent folder | download | duplicates (4)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
//  MQImageViewer.m
//  MySQL QueryBrowser
//
//  Created by Alfredo Kojima on 4/28/05.
//  Copyright 2005 MySQL AB. All rights reserved.
//

#import "MQImageViewer.h"
#import <MySQLToolsCommon/mxUtils.h>

@interface MQDraggableImageView : NSImageView
{
}
@end

@implementation MQDraggableImageView
- (void)mouseDown:(NSEvent *)theEvent
{
  NSSize dragOffset = NSMakeSize(0.0, 0.0);
  NSPasteboard *pboard;
  NSRect rect= [self frame];
  NSSize imageSize= [[self image] size];
  NSRect imageRect;
  NSPoint pt;

  pt= NSMakePoint(NSMidX(rect),NSMidY(rect));
  imageRect.size= imageSize;
  pt.x-= imageSize.width/2;
  pt.y-= imageSize.height/2;
  imageRect.origin= pt;
  if (NSPointInRect([self convertPoint:[theEvent locationInWindow] fromView:nil],imageRect))
  {
    pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
    [pboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:self];
    [pboard setData:[[self image] TIFFRepresentation] forType:NSTIFFPboardType];
    [self dragImage:[self image] at:pt offset:dragOffset 
              event:theEvent pasteboard:pboard source:self slideBack:YES];
  }
}
@end


@implementation MQImageViewer

+ (BOOL)canDisplayData:(NSData*)data
{
  if ([NSImageRep imageRepClassForData:data])
    return YES;
  return NO;
}


- (id)initWithData:(NSData*)data
{
  self= [super init];
  if (self)
  {
    NSRect frame;
    _image= [[NSImage alloc] initWithData:data];
    frame= MXRectWithSize([_image size]);
    _imageView= [[MQDraggableImageView alloc] initWithFrame:frame];
    frame.size.width+= 2.0;
    frame.size.height+= 2.0;
    frame.size= [NSScrollView frameSizeForContentSize:frame.size
                                hasHorizontalScroller:YES
                                  hasVerticalScroller:YES
                                           borderType:NSGrooveBorder];
    _scroll= [[NSScrollView alloc] initWithFrame:frame];
    [_scroll setDocumentView:_imageView];
    [_scroll setHasVerticalScroller:YES];
    [_scroll setHasHorizontalScroller:YES];
    [_scroll setBorderType:NSGrooveBorder];
    [_scroll setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
    [_imageView setImage:_image];
    [_imageView setImageAlignment:NSImageAlignCenter];
    [_imageView setImageFrameStyle:NSImageFrameNone];
    [_imageView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
    [_imageView registerForDraggedTypes:
      [NSArray arrayWithObject:NSTIFFPboardType]];
  }
  return self;
}

- (void)setData:(NSData*)data
{
  NSImage *image= [[NSImage alloc] initWithData:data];
  NSRect frame= MXRectWithSize([image size]);
  
  [_imageView setFrame:frame];
  [_imageView setImage:image];
  [image release];
}

- (NSString*)label
{
  return @"Image";
}


- (NSView*)view
{
  return _scroll;
}


- (void)setEditable:(BOOL)flag
{
#ifdef MAC_OS_X_VERSION_10_4
  [_imageView setAllowsCutCopyPaste:flag];
#endif
}


- (void)dealloc
{
  [_image release];
  [_imageView release];
  [_scroll release];
  [super dealloc];
}

@end