Working With Bitmap Images; Document-Based Application Redux
Pages: 1, 2, 3, 4, 5
Setting Document File Types in Project Builder
Before we have a functioning image viewer application we have to tell Project Builder what file types are supported by ImageApp. The place for making these changes is under the Targets tab, and within Targets under Application Settings. In this view, scroll down to the section labeled Document Types. Here you will see a table and several text fields for inputting information about document types. The table shows the document types currently supported by the application.
![]() Here is where we change the document types for the application. |
Reading the documentation related to NSImage reveals that this class supports a number of image file formats out of the box: JPEG, GIF, PNG, TIFF, PICT, PDF, BMP, EPS, and raw, untagged image data.
Highlight the default entry in the Document Types table and let's make some changes. In the fields below we want to change the name to JPEG -- the name can be anything you like, but it's best to keep it relevant. Under Extensions list the possible file extensions that can be expected for a JPEG. Type in "jpg jpeg JPG JPEG" (with or without the quotes, it doesn't matter). Spaces separate the various extensions.
Now, under OS Types we want to put the four-letter type code for JPEG, which is JPEG. Finally make sure the document class is MyDocument, and the role is Viewer. To commit the changes click on the Change button.
We now want to add entries for the other supported file types, so make the changes shown in the table below for each file type and then click the Add button, rather than the Change button. The role for these types will be Viewer, and the document class will, of course, be MyDocument.
| Name | Extensions | OS Type |
| JPEG | jpg jpeg JPG JPEG | JPEG |
| GIF | GIF gif | GIFf |
| PNG | png PNG | PNGf |
| TIFF | tif tiff TIF TIFF | TIFF |
| PICT | pct pict PCT PICT | PICT |
| pdf PDF | "PDF " | |
| BMP | bmp BMP | "BMP " |
| EPS | eps EPS | "EPSF" |
The two OS types in quotes are those that have a space at the end. OS types are four-character codes, and the ones for PDF and BMP have a space as their fourth character. We're not going to add support for raw image data, as that would require the user to provide information about the image before it can be displayed, and we don't have an interface set up to do such a thing.
By the way, if you're curious about how you can determine the OS Type for a particular file, Apple provides as part of the developer tools installation a command line utility found in /Developer/Tools called GetFileInfo. When you run this tool with a file name supplied as an argument it will print out information about that file, including the type code -- that's how I determined the type codes in the list above.
When Project Builder compiles an application the information from the Document Types table is put in the file Info.plist, which is found in the Contents directory of your application's bundle. If, after compiling and running your application, you find that you can't open up these file types, try doing a clean build of your project by clicking on the broom icon in the toolbar, and then building your project again. This will delete the old Info.plist and make a new one.
Finally we have an image viewer application. After a quick compile and run you should be able to open up the indicated image file formats and zoom and scroll around.
Before we close shop for the day, I have one last tidbit I would like to add. What we're going to do now is add another feature to our application that will make the user experience a bit more enjoyable. We're going to add some code that will do a type of validation on the scroll bars in the scroll view. Let's go on with this now.
The Scroll Bars
The thing about scroll views is that by default the scroll bars are always present, even if the contents of the scroll view are significantly smaller than the scroll view itself.
|
Also in Programming with Cocoa |
What we're going to do now is implement some code that will compare the size of the view to the size of the scroll view, and based on that comparison hide or show the scroll bars. This validation will be done in IAImageView, and the name of this method is -validateScrollers. We will invoke this method before doing anything else in -drawRect:. So going back to -drawRect: in IAImageView, we add:
- (void)drawRect:(NSRect)rect {
[self validateScrollers];
[super drawRect:rect];
}
When overriding -drawRect: in a subclass of NSImageView we must be certain to send a similar -drawRect: message to super so the NSImagePart of IAImageView has a chance to render the image.
So the premise of -validateScrollers is easy enough. If the width of the image view's frame is greater than the width of the scroll view, then we show the horizontal scroller. If not, then we hide that scroller. The same goes for the vertical scroller: if the height of the image view's frame is greater than the height of the scroll view's frame, we show the scroller -- if not, we hide the scroller. We can set whether the scroll view has a horizontal or vertical scroller by sending -setHasHorizontalScroller: or -setHasVerticalScroller: messages, respectively, which take BOOL arguments. Let's now take a look at the code:
- (void)validateScrollers
{
NSScrollView *scrollView = [[self superview] superview];
NSSize selfSize = [self frame].size;
NSSize sViewSize = [scrollView frame].size;
BOOL hFlag = selfSize.width > sViewSize.width;
BOOL vFlag = selfSize.height > sViewSize.height;
[scrollView setHasHorizontalScroller:hFlag];
[scrollView setHasVerticalScroller:vFlag];
}
In the first line of this method we access the scroll view by sending a superview message to self (IAImageView), and then another superview message to the view returned by the first superview message to self. What is a superview, you ask? In Cocoa, views within windows are arranged within a spatial hierarchy. That is, a view has one superview, and one or more subviews.
In our application, IAImageView is at the bottom of the hierarchy, and the content view of the window is at the top of the hierarchy. IAImageView's superview is an instance of NSClippingView, whose superview is in turn the scroll view. The superview of the scroll view is the content view of the window.
But that's not the whole story. NSScrollViews, in addition to having an NSClipView as a subview, have NSScrollers, which descend from NSView. So the scroll view has three subviews -- the two scrollers and the clip view. Likewise, the window's content view has two more subviews in addition to the scroll view; they are the two text fields at the bottom of the window that make up our zoom control.
The image below shows a schematic representation of this hierarchy in our document window.
![]() The view hierarchy for our application's window. |
So by invoking superview twice, we step up two views from IAImageView in the view hierarchy to retrieve the scroll view.
Moving on with the code, we retrieve the sizes of the frames for the view and the scroll view. In the following two lines we have two BOOL variables, hFlag and vFlag, whose values are the results of the comparisons shown on the right side of the assignment operators.
Essentially, if the width of the view's frame is greater than the width of the scroll view's frame, then hFlag is YES. Likewise for vFlag in the y-direction. These two BOOL variables are then passed as arguments to -setHasHorizontalScroller: and -setHasVerticalScroller:. And that's all there is to it.
By calling [self validateScrollers] in drawRect:, we will have the scrollers appear and hide in real-time whenever the view's contents are redrawn.
Conclusion
Today's column was a long one. Here is the project folder for ImageApp to help you digest this mess of information. I had intended to throw a lot more stuff at you, but as I wrote I realized I had created a monster. In fact, the concept that impelled me to write this app, and that I wanted to write about, now won't see the light of day for another two columns! So while this column had -- in my opinion -- some pretty interesting pearls of wisdom, it was ultimately a foundation for even more interesting things to come.
In the next column you can look forward to implementing a fairly nifty save method, filled with lots of good info about images and image reps. We will also implement some smart, window-zooming behavior, and even printing. So see you next time.
Michael Beam is a software engineer in the energy industry specializing in seismic application development on Linux with C++ and Qt. He lives in Houston, Texas with his wife and son.
Return to the Mac DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 37 of 37.
-
How do I open image into existing Window
2003-04-07 17:57:33 dromidror [Reply | View]
How do I program a single document application? The application creates an empty window on launch. The opened document should use this single window to display its graphics.
-
Converting to Cocoa-java
2002-06-27 12:34:56 arosen [Reply | View]
Hi,
Although the tutorial is in Objective-C, I tried to follow the tutorial using java instead. I hope someone can help me out.
Two problems have evolved and I'm not sure if the second one is related to the first.
Problem 1: In Interface Builder, I want to add the action changeScale to IAWindowController. However, when I type it in, it's replaced by the message "<invlaid number of arguments>".Any other similar method name works(eg changeScales,etc).
I see a similar problem when creating IAImageView. In this case I don't add any new actions, but when I change the file type from Obj-c to Java, the first method listed in the actions (which is inherited from NSImageView and therefore cannot be changed) turns into the same message I mentioned before.
Problem 2: The app compiles fine except that when I build and run, I get the message "2002-06-26 11:23:01.413 ImageApp[662] *** file inconsistency: read '@', expecting 'C'"
and then
"ImageApp has exited due to signal 11 (SIGSEGV)." and the app dies.
Any help would be greatly appreciated.
Thanx
Avi
-
Centering the View
2002-05-29 01:52:48 jimdex [Reply | View]
When you enlarge the image window, the image is located at bottom left. How to center the image in the window ?
-----------------------------------
Jean-Michel DAIX / <jim@adforum.com>
Sorry, I’m French !
visit <http://www.adforum.com>
-
validateScrollers question
2002-05-05 04:42:15 sjmiller [Reply | View]
As written, validateScrollers does not immediately remove the scrollers if the image is rescaled to fit within the current window. The area occupied by the scrollers is not updated. I partially fixed this by adding the following line to validateScrollers:
[[[self window] contentView] setNeedsDisplay:YES];
But, even with this line, the scrollers go away, but the pin striped background is not redrawn until you click on the resize area of the window. What am I missing? -
validateScrollers question
2002-10-03 02:50:15 stupidfish23 [Reply | View]
just add the line
[view validateScrollers];
to your scaleImageTo: method.
so it basically looks like:
- (void)scaleImageTo:(float)_scale
{
if(_scale>0)
scale=_scale;
[view scaleFrameBy:scale];
[zoomControl setFloatValue:(scale*100)];
[view validateScrollers];
}
it works great for me.
stupidFish23
-
hard drive room for developer doc's
2002-05-04 09:31:04 psheldon [Reply | View]
I made several hard partitions on my powerbook G4 to act as separate hard drives with different operating systems or simply work areas. I feel more secure this way.
The last developer doc's were so huge and would only go on the os x boot drive. Apple was working on a better method.
Maya-PLE would only dumb install on the boot drive and I foresaw a problem of future room on my hard partition that has the os x boot. So, I finder moved Maya to another hard partition
I've continued using Maya without too much trouble from the move, except that file>recent files doesn't find the pathnames therein. I'd like something less invasive than superuser do's changing .rlogins, but fear something too heavy for Industrial Light and Magic. A simpler fix might have us all be famous with George Lucas. Any takers? Bob Levitus spoke of symbolic aliasing on the boot disk fooling the system into thinking Maya was there, but, bumping around digital asset management free seminars, I realized aliasing concepts are deeper than this poor pate to complain about not looking like somebody else's unix.
Well, now I am going to do a developer's tools install that may lose me Maya's recent forever. Kind of scary...
-
emergent communities...
2002-05-03 13:01:29 psheldon [Reply | View]
I am extremely interested in emergent communities of users as I am eventually wanting to get a post doc with a good mentor relationship guaranteeing publication and ultimate tenure.
I have joined the Maya-PLE community, but so far am extremely shy about asking or answering questions. Every once in awhile I force myself to peek at what's going on and say something heartening.
Apple is developing knowledge navigation in their hyperlinked documents of Help Viewer, but I need a "baby problem book" to make me have any confidence in either Maya or Apple winging it on my own.
Monday night, I had teenagers challenge me on using Maya. My hands weren't being held by walking through the Lessons.pdf which tells you exactly what to do. I fixated on a wrong approach to the challenge and then broke free with an obvious, in hindsight, answer to the teenagers challenge. When next I got into a fixation and had to do operant behavior with a three button mouse, I lost their attention.
According to Deborah Tannen, a masculine conversation style is concern for looking good in performance, but I fear that what I must teach a teenager in the fourth Piaget stage is another concern, a concern for process. That might be distinct from Tannen's alleged feminine concern of bonding of the community. I think the teenagers lost their attention during my operant behavior with the 3 button mouse or maybe they were going to lose their attention span anyway because the information was rather dense.
Nonetheless, I had their attention for a bit and during that bit I may have shared a little process because I asceded to their challenge. Their challenge afforded me with that "baby book of problems" I sorely needed. When I started to respond, I had no idea that I could because I had never responded before. I was scared. I warned them that I might share process and, if they expected prepared performance, they would lose respect and attention for me. But I grinned to indicate that sharing process was a brave thing I had to try to do.
I am now going to try to respond to michele's question about "drag back". I don't know whether I can do it, but I shall be brave and put myself "out there" and risk "losing status", as Deborah Tannen would say. Risking beyond my comfort zone is essential to be a Jungian or Campbellian. Forgive me.
Dragging from a file to a window produces a single type, I suppose, image or bitmap that shows on the screen. Embedded in quickdraw of os 9.x are application specific comments which can be both active or inactive in other applications you paste to. I know this because I pasted equations from software called Weinberg into another software called Acta to use an outliner to organize and compose complex ideas in graduate level mathematics and physics. When an application doesn't understand another application's application-specific comments, it neither acts on them, nor throws them out. There are some sort of levels of interpretation in the clipboard, but the whole thing is there.
What michele did with titling by a pathname suggested that maybe the os x operating system might keep reference to the dragged from file no matter how it interprets in the reduced bitmap representation. So it hasn't actually lost information in the whole file. All I am saying is maybe systems designers of os x designed os x like this. As they are wiser than me, they might have reasons for not doing this, dare I say "pass by reference". If they were so motivated by their wiser design decisions, then a drag from a pict in a window might know the file refered to and make it like a drag from the file. Now, as a devil's advocate to such a motivation, wouldn't I want something distinct from a drag from a file or I'd do a drag from a file? Also, what would be the new meaning of a drag to the finder window, copying of the file? If gestures don't do something new, are they merely a cost rather than a prize?
So, michele's question becomes a question of meaning in the desktop interface, the foundations of design of os x. This is very interesting.
Tannen works in Washington D.C. at Georgetown University, where concern for protocol can have world shattering consequence. I became so embarrassed about protocol that I was afraid that some person might agree with me and say I should be embarrassed and then I'd never get to talk in colloquia dispite the fact that I was cited as inspirational in a paper on quantum gravity in the lab. It doesn't take much to inspire, unless people fear that you will get overbearning from pride. I didn't want the reward for my victory to be to have someone say shut up to me. So, after I was cited, I became extremely embarrassed abou protocol, lest I associate victory with pain and never be victorious again.
However, I took a break from worrying about protocol to read a follow up to Kurzweil's "Age of Spiritual Machines", the followup book recommended me by Amazon.com's robot, "Mind at Lightspeed". In it, I reminded myself of my extreme curiousity about language and interface itself as reflecting the peronsal power (as opposed to worry about interpersonal power etiquette) of Jean Louis Gassee in "The Third Apple". They are talking about the parallelism of a visual system and whole images as opposed to bits in sequence of conversation and the potentialities of a networked parallel community of nodes. I think one can obsess about protocols and miss the wonder of the subject that can transport you to a peaceful place away from such heat.
Sometimes I go on adventures with my old dog and visit universities and talk in professors offices, just shoing I'm interested and being relieved that they can no longer think of me as a graduate student who is after something or worse someone in their public relations staff. Still, such conversations have the anxiety of my performing well in them or at least the expectations of parties not present that I report performance to them. It is such a relief to go into the woods with my dog and take a vacation from interpersonal protocols and etiquette and just get into my perosnal power by reading a textbook and solving problems for the heck of it.
Santa Fe Institute, where scientists of different styles get together, has now taken to have people come by invitation only. This saddens me because I did so enjoy going to lunch with folks there and just talking science friendly and not in any way associated with "having" a position and doing work "for" somebody. It had been a place of personal power of Gassee.
talking here is < $5 < WWDC and a good place to wet my feet.
Its so good to see a live audience out there making programs in cocoa while I'm still afraid of knowledge navigation in Help Viewer to figure the constructs out for myself.
Well, enough poetry. Next time I'll do better.
-
Some questions
2002-04-27 17:10:38 michele [Reply | View]
Hello Mike,
Could you please in the future explain us how to make a view a drag source.
I've tried to implement it, but failed (always received a signal 11).
Thanks in advance,
Michèle -
Some questions
2002-05-09 09:04:42 Michael Beam |
[Reply | View]
You bet! I'll be sure to fill you in on that in a future column. We'll be working on this app for several columns, so it will fit right in.
Mike
-
Making the view a dragging destination
2002-04-27 17:05:11 michele [Reply | View]
Here is my implementation of drag and drop.
Making the view a dragging destination
Add the following methods to IAImageView.m:
1 - Register for dragged types when initializing the image view
- (id) initWithCoder: (NSCoder *) coder
{
if (self = [super initWithCoder: coder])
{
[self registerForDraggedTypes: [NSImage imagePasteboardTypes]];
}
return self;
}
2 - At the beginning of the dragging operation, set a flag to highlight the view if the pasteboard contains a valid image and the dragging operation is copying
Declare the flag in IAImageView.h
BOOL highlight;
Implement the method in IAImageView.m
- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
{
if ([NSImage canInitWithPasteboard: [sender draggingPasteboard]] &&
[sender draggingSourceOperationMask] & NSDragOperationCopy)
{
highlight = YES;
[self setNeedsDisplay: YES];
return NSDragOperationCopy;
}
return NSDragOperationNone;
}
3 - Whenever the mouse quits the dragging destination, set a flag to unhighlight the view
- (void) draggingExited: (id <NSDraggingInfo>) sender
{
highlight = NO;
[self setNeedsDisplay: YES];
}
4 - Check if the pasteboard contains a valid image
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
{
highlight = NO;
[self setNeedsDisplay: YES];
return [NSImage canInitWithPasteboard: [sender draggingPasteboard]];
}
5 - Performs the dragging operation
- (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
{
// Don't drag if the source = the destination
if ([sender draggingSource] != self)
{
NSURL *fileURL;
// Check if there is a valid image in pasteboard
if ([NSImage canInitWithPasteboard: [sender draggingPasteboard]])
{
// Insert the image into the view
[[self image] initWithPasteboard: [sender draggingPasteboard]];
// Rescale the image to the current scaling value
[self scaleFrameBy: [[[self window] delegate] getScale]];
}
// Retrieve the name of the file
fileURL = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
if (fileURL != NULL)
{
// Set the window title to the name of the file
[[self window] setTitle: [fileURL absoluteString]];
}
else
{
[[self window setTitle: @"(no name)"];
}
}
return YES;
}
6 - Change the drawRect method to display a border around the dragging destination
Add the following at the end of the method
if (highlight)
{
[[NSColor grayColor] set];
[NSBezierPath setDefaultLineWidth: 5];
[NSBezierPath strokeRect: rect];
}
7 - Add a method to IAWindowController.h to get the current scale value
In IAWindowController.h
- (float) getScale;
In IAWindowController.m
- (float) getScale
{
return ([zoomControl floatValue] / 100.0);
}
8 - Add #import "IAWindowController.h" in IAImageView.m for the getScale method
-
Making the view a dragging destination
2002-05-02 21:17:46 psheldon [Reply | View]
Step 5 had a syntax error one of the self windows didn't have a right enclosing square bracket.
Evidentally, not all methods need be mentioned in the header file, rather these are only used in the name space of the implementation. What are such methods called?
When I made a new window from the file menu item, it always came in with my default gif, Yoda.gif, but I could still drag another gif onto that window and Yoda would be supplanted. Does this cause memory leak or is the old image in ram automatically released?
You've commented not only the code but also the e mail about the code and that's good, but I am green at this stuff.
initWithCoder evidenced itself as an override with the message to super and that fact that, though it was restricted to the name space of IAImageView.m, there was not visible call to it there.
Help Viewer with initWithCoder asked kind of scared me, but I've faced the deamons and stared down code before.
Registering intuits to me like something of abstract generality that those who speak this stuff know as so fundamental it probably isn't documented formally.
There seems something that looks like type coercion of a sender which also strikes me with wonder.
I liked the draggingEntered and draggingExited touch and it clearly illustrated distributed code in oop with drawRect.
I also remark at all this sender machinary doesn't require wiring work, dragging is built into the frameworks, but perhaps there's a hypothetical drag event filter in the hypothetical forced typing? I'd really like to get clear what is going on with the syntax here. I don't like making too many hypotheses.
To be contrary, I tried dragging Dennis Gabor's nobel lecture pdf to the window and got the first page complete with figure, but I didn't get the "whole picture" (35 pages).
;-)
Hard to imagine something I almost understood dealing with decoding and rendering pdf's.
When I started looking at this drag code, I really wondered if I had anything to say or anything that I understood by it. At first I felt dwarfed by this drag development, but I feel much better about it having tried to write about what I saw, not so much a dwarf.
I hope, not to "one up", but rather to amplify people by commenting on what they say.
There was this Chinese guy I could barely understand through the accent talking about Higgs symmetry breaking in particle physics (nobel level stuff) and only the fellow who introduced him dared to ask him a question. I feared his response to anything would be so incomprehensible I could not show thanks in my face. A dead audience can eventually wear you down, so I wrote him very politely an e mail on what I understood about what he said. He told me when I was right and gave brief provacative answers where I still am thoroughly confused, but not as much as before he answered my e mail. The e mail had no confusing accent. I did refrain from asking a followup on where I remained confused, but rather thanked him and voicemailed a local prof (the guy who introduced the speaker). I think both I and the speaker were happier for the transaction and both a bit wiser. I'm terribly sorry that all colloquia are over this semester, because follow up e mails are both not intrusive as questions at the colloquia and provide a way to study the notes merely requiring corrections from the speaker.
-
Making the view a dragging destination
2002-05-03 12:34:15 michele [Reply | View]
Hello p,
"Evidentally, not all methods need be mentioned in the header file, rather these are only used in the name space of the implementation. What are such methods called? "
They are inherited, so you don't need to put them in the header file, but you can. Do what you feel.
"When I made a new window from the file menu item, it always came in with my default gif, Yoda.gif, but I could still drag another gif onto that window and Yoda would be supplanted. Does this cause memory leak or is the old image in ram automatically released?"
No, it's designed so that there is no memory leak. You can test it with ObjectAlloc (in Developper Applications). Launch ObjectAlloc, put a few breaks in strategic places in your code in PB, debug compile, open your debug built in Object Alloc and watch your own classes.
"initWithCoder evidenced itself as an override with the message to super and that fact that, though it was restricted to the name space of IAImageView.m, there was not visible call to it there. "
If you want to see when a part of your code is called, put a descriptive NSLog message in all methods so near as the beginning of the code as you can (I mean, after the variables), say NSLog(@"Enter mymethod"); Then debug run. You'll have a trace of all calls: yours and the underlying ones.
"To be contrary, I tried dragging Dennis Gabor's nobel lecture pdf to the window and got the first page complete with figure, but I didn't get the "whole picture" (35 pages). "
I'm not sure, but I remember playing with Preview and Acrobat for pdfs. Try to change the application to open the pdf (either Acrobat or Preview). I know one of them gives you the whole file (just don't remember which one).
Drag and drop is explained in Programming Topics.
Michèle
-
is Programming Topics a pdf?
2002-05-09 07:08:32 psheldon [Reply | View]
Looked for it with Sherlock. There are many many pdf files. I recall something about ApKit from long ago where I started to read about model view controller but felt not wise enough to follow then. I might like to read such a text now. -
both Acrobat and Preview show whole pdf
2002-05-09 06:54:38 psheldon [Reply | View]
The drag operation to your application only gets the first page into an image. -
Making the view a dragging destination
2002-05-05 21:49:21 dallasmac [Reply | View]
I added the drag and drop code, but dragging an image only works after I have opened an image.
Is there a way that the drag event work when the inital window appears.
Thanks
Steve -
Making the view a dragging destination
2002-05-06 13:19:45 michele [Reply | View]
Basically no, because while dragging an image you put the data (raw, bitmap, etc..) in a NSImage which will be put in turn into an NSImageView.
That's why you need an existing NSImage (even transparent one) to drag another into it. See the Composite Lab example in AppKit for more details.
Michèle
-
Adding loading an image at launch time
2002-04-27 17:03:17 michele [Reply | View]
With the aim of implementing drag and drop in the application, I've added the loading of an image at launch time.
Loading an image at launch time (another option is to run a modal panel to force opening a file).
1 - Make a tiff image. Add it to the project (with copy items ... if needed checked).
2 - Add a method to MyDocument.h to load the image
- (void) setActiveImage: (NSString *) aString;
3 - Implement the method in MyDocument.m
- (void) setActiveImage: (NSString *) aString
{
activeImage: [NSImage imageNamed: aString];
}
4 - Change the windowDidLoad method in IAWindowController.m
- (void) windowDidLoad
{
NSImage *image;
if ([[self document] activeImage] == nil)
{
[[self document] setActiveImage: @"lave"];
}
image = [[self document] activeImage];
[view setImage: image];
[self scaleImageTo: 1.0];
}
if the loaded image is named lave.tiff, just give the name without extension as parameter to setActiveImage.
-
Adding loading an image at launch time
2002-05-02 12:56:07 psheldon [Reply | View]
Recent file functionality in ImageApp. Where can I look to see the pathnames of the images I opened that supply this recent?
Step 3 had colon instead of equal sign. When I corrected this typo, your work worked.
In a folder I called thread, I both saved your notes html source from IE and pasted from the browser rendering. That way I invented a subcolumn organization for myself. If only I knew how to save all notes and columns and make them a "search network" for Help Viewer. Help Viewer does use html source sometimes obscured by folders only accessible by control mouseclick's "show contents".
Thanks for your work.
-
Some changes
2002-04-27 17:00:43 michele [Reply | View]
I've made some changes to avoid warnings at compile time, improve image scaling, and avoid memory leaks.
I - To avoid warning at compile time:
1 - Warning: IAWindoController does not respond to scaleImageTo
Added in IAWindowController.h the declaration of:
- (void)scaleImageTo:(float)_scale;
2 - Warnings: cannot find method
return type for 'activeImage' defaults to id
Added in IAWindowController.m:
#import "MyDocument.h"
II - To avoid incorrect redrawing of image when scaling (image drawn over scrollers)
1 - Change in (void) scaleFrameBy: (float) scale in IAImageView.m
Replace: [self setNeedsDisplay: YES];
by: [[[self window] contentView] displayIfNeededIgnoringOpacity];
As the scrollers are opaque, we need to force a complete redraw.
2 - Add in (void) validateScrollers in IAImageView.m
at the very end: [scrollView tile];
Forces a redraw of scrollView, clipView, scrollers, and ImageView taking into account the opacity (does not redraw the opaque parts).
III - To avoid memory leaks
1 - Add
[windowController release];
at the end of - (void)makeWindowControllers in MyDocumemt.h
2 - Change - (BOOL) loadDataRepresentation: (NSData *) data ofType: (NSString *) aType in MyDocument.h
- (BOOL) loadDataRepresentation: (NSData *) data ofType: (NSString *) aType
{
activeImage = [[[NSImage alloc] initWithData: data] autorelease];
return (activeImage != nil);
}
-
Some changes
2002-07-14 12:04:04 blukens [Reply | View]
My solution to the poorly drawn scroll bars was to just change
[self setNeedsDisplay: YES];
to
[[[self superview] superview] setNeedsDisplay:YES];
The problem we had was that the original line just refreshes the imageview, so the scroll bars are being refreshed and therefore don't go away when they should. The new line sets the entire scrollview to be refreshed, which is exactly what we want. -
Some changes
2002-05-02 09:24:31 psheldon [Reply | View]
Sorry I have been out wandering in wierd science and virtual reality and missing communication on this thread.
I see a neat professional subject line, "some changes". This indicates that you have work group experience in programming I sorely lack. I hope this group emerges professionally.
In 1 you fulfilled your general check prescription you gave me.
In 2 I found I had had the savvy to do that too.
II. 1.
Wanted to step away from obvious learning by the context of what you said.
Working hypothesis : "displayIfNeededIgnoringOpacity" method might need some interesting knowledge navigation to track down the description of. I checked that hypothesis and simply put in this word into help viewer and got two hits, one for objective c. Devil's advocate hypothesis, polymorphism requires hit on one word rather than going through chain of types and their methods for uninteresting or inexpensive knowledge navigation.
There was a link to this in the section but it merely went to the top. Was April's developers cd documentation fixing this? I get T1 system updates through an airport card at Apple Store Willowbend and thought I automatically got developer updates; I now don't think so and will install that cd! There was a notice in May e mail on May mailing about April developer upgrade and I might have to wait to see for sure whether April is in May. Confusing verbage somehow makes sense when you realize that the dating might be by web access, a date delayed in cd publication. Yet, April's cd stated that they had developer tools which I suppose included documentation.
Ok. I fooled with my version and saw Yoda gif drawn over scrollbars. On windows in mac old os, there are clipping rectangles with redraw avoiding outside the clip rectangles. I suppose the same design metaphor is used in the polymorphism and IgnoringOpacity means to redraw ignoring Opacity which is stated as the clipped parts.
Now, I put in your phrase. I compiled. It didn't redraw unless I clicked on scrollbar. Putting the [self setNeedsDisplay: YES]; in after your statement made things work right for me. So, I differ in your use of the word "replace" and substituted "augment". In IB, I have "surpressed" the green button on my window and that might be why I must use augment rather than replace, "I dunno".
I commented out the above hypothesizing that "As the scrollers are opaque, we need to force a complete redraw." was a transitional sentence prefatory to the next II.2. Both the experiments and your words confirmed the new hypothesis. The unfound method's phrase was just to establish clip window but not force a redraw.
III.1.
I believe makeWindowControllers thereby has MyDocument surrender ownership of WindowController to the MyDocument instance's list of window controllers. I don't know how to say this better because I don't have enough language experience in objective c.
III.2 .
I developed a gesture similar to one I use in Maple to make the change. "[]" before the expression to replace and then shift arrow across that expression, cut, arrow back, paste, space, and then type autorelease. It might be nice to applescript automate this gesture.
;-)
Thanks for the walk through of changes. It made an exercise for me. Off to workout in pool. -
Some changes
2002-05-03 12:10:48 michele [Reply | View]
Hello p,
Wooh, it's very hard for me to understand well what you say. I'm not an English native speaker, so, please, try to use only very basic words, so I can follow your ideas.
"I see a neat professional subject line, "some changes". This indicates that you have work group experience".
Just one thirty years ago (yes, 30).
"Working hypothesis : "displayIfNeededIgnoringOpacity" method might need some interesting knowledge navigation to track down the description of."
I''ve already told you of an application which you can browse the doc with. It's MarshmallowLibrarian. But since sherlock has been greatly improved with the last OS update and MarshmallowLibrarian tends to crash repeatedly on my computer, I use Sherlock (just drop the developer folder on to the main Sherlock page), index it, and give it an enclosed string to search into documents.
Another good way to learn efficiently is to browse all the examples (see composite lab and sketch for images). Whenever you find a method you don't know, use find in PB with options frameworks only. You'll get all references to the searched method. Then browse the corresponding doc. There are also shortcuts to do it.
Another excellent way to learn is to subscribe to Cocoa Apple mailing list. Read, read, read it first, then ask people. And download examples when people give you a link to.
displayIfNeededIgnoringOpacity is well described in NSView:
Acts as displayIfNeeded, except that this method doesn't back up to the first opaque ancestor-it simply causes the receiver and its descendants to execute their drawing code.
The April Developer Tools CD is online now for all ADC members. If you have, as I do, a slow connection, you'd better buy it (20$). It's an about 243 Mb download. I've bought it on April 24th and received it today (I'm in France).
The main advantage is that you have the whole documentation updated (no need to go to Apple site every two lines of code).
Michèle
-
Some changes
2002-05-04 09:15:00 psheldon [Reply | View]
"...use only very basic words, so I can follow your ideas..."
I've found putting ideas in shorter paragraph can also work to get through language barriers.
"""Just one thirty years ago (yes, 30)...."
I have been a scholar for 17 years and am afraid the work group has developed while I have learned to work alone not with people. I worry about my choices and other lives I might have lived. I suspect most people's work group experience is "getting along with powerful people". I've had that with my thesis advisor because I gave him power by investing with him my life time. I want another sort of work group experience... Don't know what that could be.
Please compare sherlock indexing string search to Help Viewer. As soon as I asked this question, I imagined your answer. Help Viewer doesn't have find but an html browser does and probably string search gets you right to the instance of the words.
MarshmallowLibrarian:
I downloaded MarshmallowLibrarian, enough documentation on web page, the pictures and comments on this page were reassuring and seemed enough, so I turned web page into pdf file. I used sherlock 2 internet channel to find it.
"...browse all the examples (see composite lab and sketch for images). "
I couldn't understand this. By "browse" do you mean use a web browser such as netscape or internet explorer? If that is what you meant by browser, I understood that part. I think I might drag the example folder into sherlock and augment web browser to give meaning to the phrase "browse all the examples" to indexed enclosed string search examples. But, "see composite lab and sketch for images" confuses me still. Maybe sketch is an application and is also "composite lab" an application?
In making guesses, I ease your language embarrassment. It is easier to read than write a foreign language (at first) and allowing you to answer yes or no will give you great energy, just like that Chinese fellow I asked about nobel level stuff with "do I understand you to mean....".
"...use find in PB with options frameworks only..."
I know command 7 finds everything, both my code and frameworks. Now I will look for setting options. Very good.
"... There are also shortcuts to do it. ..."
Knowing that something is out there to find is valuable to me. I will go find shortcuts.
I've long ago subscribed to Cocoa Apple mailing list, but I am a bit scared of it, as yet. I peek at it and Maya list, but shyly work Mike's and Maya's tutorials, so far. I'm not so shy on this thread, though.
" ... download examples when people give you a link to. ...."
This gets rid of my shyness a bit. I can play with examples and not be embarrassed I don't know the language.
"displayIfNeededIgnoringOpacity is well described in NSView"
And my putting together sherlock indexing and search with enclosed string would buy me not having to look through the huge NSView as Help Viewer would have. Perhaps Apple wishes to force new programmers to read introductions, see their doc organization, and so don't put in a find string or jump to method in Help Viewer.
The phrase you chose out of NSView seems clear enough. Thank you.
"April Developer Tools CD ..."
I get the cd mailing to get perpetually embarrassed that I am often too scared to look at it. My ultimate goal is to get so many cd's that I shall have to learn the respect for hypertext and search strategies you have. I believe that April mailing had general os 9 including tools, but May mailing has os x specific tools. Now, I have more courage to look inside and see.
Thank you! -
Some changes
2002-05-06 13:35:01 michele [Reply | View]
Hello p (what's your first name please, p sounds very mathematical to me),
By "browse" do you mean use a web browser such as netscape or internet explorer?
No, excuse me, My English is very basic. I mean, read it thorougly, cut the parts of code you thing you understand and use it in your own application to experiment with.
Sketch and Composite Lab are code examples from Apple. You find them and a lot more in the Developer folder, Examples, AppKit. The Developer folder is at the first level of your hard disk.
As for the new PB, try it. You can customize the editors, use gcc 3. And what's unvaluable you have the up-to-date documentation. Personnally, I was at the border of nervous breakdown with the ever mentioned "description forthcoming" each time I needed more details on a method, a class or even a topic.
Michèle -
I am Paul, Sherlock 3 of Jaguar multithreaded
2002-05-07 22:37:00 psheldon [Reply | View]
www.maccentral.com has Jobs keynote saying it has this multithreaded feature like Marshmallow librarian has. I suspect that feature is much more than being able to search while indexing. I'd like Apple to eventually tell me something deeper about that multithreadedness being a good feature.
I'm going to fool with Marshmallow librarian.
I think there are general things I don't understand about indexing, whether with sherlock or Marshmallow librarian. Where, for example, is the index saved or is it saved?
I installed the May 2002 cd mailing mac os x developer tools. There was also a disk with developer tools in April. So, to make an April fools joke, I might be fooled as to which was the April tools. They usually have distinct things in different months and two months of tools is surprising. So, I may really be fooled.
I copied and recompiled and old project in Applescript and then did the "Variables Inside Cocoa Objects" of 04/12/2002 in the new PB. The readme on the May cd mailing tools said that headers were precompiled and so builds were faster. I think they were.
Exciting. -
I am Paul, Sherlock 3 of Jaguar multithreaded
2003-06-10 16:36:20 anonymous2 [Reply | View]
no i am paul sherlock 3 of jaguar multithreaded
i will unleash my power on all of you! -
I am Paul, Sherlock 3 of Jaguar multithreaded
2002-05-13 03:59:57 michele [Reply | View]
Hello Paul,
The indexes you create with MarshmallowLibrarian are saved in Users/Library/Application Support/MarshmallowLibrarian/Index. Whenever you launch the application or a saved file, the program loads the indexes.
As for Sherlock, I think the indexes are encoded into the com.Apple.Sherlock.plist file which is located in Users/Library/Preferences folder.
Michèle
-
@class IAImageView supplemented by *,h
2002-04-24 07:50:31 psheldon [Reply | View]
I had been happy to see how to make drawRect work by realizing that the call to superclass wasn't "understood" when an override stub was in place. I believe it is ambiguous to generally comment what order to put the superclass call or apple would have put this call in the stub.
This morning, I downloaded the working code of ImageAppTest. I was curious I hadn't gotten "@class IAImageView" to work and why. Now I saw that that was a trick only for headers.
I think one would say that, in a complex project, while one has a lot of headers and IBOutlets but hasn't actually implemented calls that need definition the "@class IAImageView" construct in those headers cuts down on distracting compiler complaints, but as soon as one implements methods of the object in the .m files, they need definition.
As I recall, "import" as opposed to "include" "recursively but nonrepeatedly includes" header import. It would be nice if I could attempt to write something in summary commenting these three language choices of the objjective-c developer :
1. #include
2. #import "*.h"
3. #import @class * //without .h
Draft comment summary :
3 while my .m stubs don't mention methods of IBOutlets speeds up compilation, 2 places used IBOutlets method definitions at the disposal of .m implementations only after you need them, and 1, I suppose, as if text were there.
If I am wrong or anyone wants to rewrite this summary, I believe it might be a good exercise. I hope this effort helps us code.
-
@class IAImageView supplemented by *,h
2002-04-26 04:28:14 michele [Reply | View]
Hello sheldon,
For what I've understood from practise:
1 - Don't use #include at all while coding in Cocoa.
2 - Use #import:
- in implementation files:
- for the proper header,
- for other headers, when you've used the corresponding @class methods in the header file, and when there is some code which uses variables or calls to methods from thoses classes
- in header file, when your your header file uses static variables defined in other class.
3 - use @class in header files n other situations, in this case don't forget to #import the corresponding header in the implementation file if needed.
Best way to determine what to #import or @class:
don't include anything and build your code, adding #import or @class step by step, rebuilding after each addition, and soon you'll discover what to do in each case, though some cases might be not so obvious.
Michele
-
@class IAImageView syntax misunderstood
2002-04-24 08:40:08 psheldon [Reply | View]
Column wrote :
#import
@class IAImageView;
and I interpreted carriage return as white space.
Should have read :
#import ...
@class IAImageView;
So, I had missed 2 things :
1. need for #import in .m when implementation mentions methods of
IAImageView
2. syntax before this need.
-
Build Warnings
2002-04-21 00:09:41 johnts [Reply | View]
First, I had a tough time just to get it to display an image. I ran it before adding the scroll stuff and it would not display any images. I added the scroll bits and then it would display the images. Don't know why.
Second, there are a couple of warnings when it is built:
IAWindowController.m: In function `-[IAWindowController windowDidLoad]':
IAWindowController.m:16: warning: cannot find method.
IAWindowController.m:16: warning: return type for `activeImage' defaults to id
I (just) fixed it by adding #import "MyDocument.h" to IAWindowController.m
There was also another warning:
IAWindowController.m:19: warning: `IAWindowController' does not respond to `scaleImageTo:'
That I fixed by adding the scaleImageTo to the IAWindowController.h file.
-
Build Warnings - no image displayed
2002-04-21 09:12:12 jreno [Reply | View]
The reason you cannot get an image to display before you add the scrolling bits is because of the 'drawRect:' implementation. If you add [super drawRect:rect] in '-(void)drawRect{}' it will work just fine without the scroll-stuff.








I'm new with objective-c.
I did the app step by step.
When i run it, everything seems to be ok, but when i try to open a file, nothing happens. Even the interface doesn't appear.
What could be the reason?
Thnx.