1

I am creating a Cocoa application wherein one view will contain the "hex dump" of the currently loaded document. Up until this point, I have been using a bog-standard (and very unappealing) NSTextField, but I am now looking for something more powerful.

I am a great fan of 0xED.app and would love to replicate its main "hex dump" view. How would I go about doing this?

I'm not necessarily after the eye-candy, but the ability to select a range of bytes without also selecting the offset or text columns. I am a loss as to where I would even begin to implement this effectively. Surely this is not drawn upon a blank canvas?

0xED screenshot

skaffman
  • 398,947
  • 96
  • 818
  • 769
Aidan Steele
  • 10,999
  • 6
  • 38
  • 59

3 Answers3

0

If you want to take a look at how a Cocoa interface is built you can use NibToXibConverter.

  1. Download 0xED, right click on 0xED.app and select "Show Package Contents". Extract the Contents/Resources/English.lproj folder.
  2. Run NibToXibConverter, browse to the folder extracted above, and put a tick next to "Decompile NIBs".
  3. Select the "Convert" button and it will convert the NIBs to XIBs
  4. Double click a XIB to open it in XCode and you can see how they are constructed

    • You will note that in the case of 0xED he is using a custom class (most likely a subclass of UIView with custom drawing as Jon Hess suggests).
headkaze
  • 469
  • 4
  • 11
0

My guess is that it's probably accomplished using a NSTableView or subclass of it.

It might be a little tricky to get the correct text selection accomplished this way, but it's probably possible.

user160917
  • 9,211
  • 4
  • 53
  • 63
0

To get started and see how things basically work:

  1. Subclass NSView.
  2. Add an instance variable to hold your NSData.
  3. Override drawRect:

This approach will be slow for a large amount of data, but will give you a good handle on implementing a NSView subclass. After that, you'll want to improve the drawing performance by implementing something better than repeated calls to draw strings one at a time. You'll also want to implement overrides of methods like mouseDown: and keyDown: to handle input from the user to allow things like selecting a range of bytes.

That should get you started, once you have that going, I'd suggest asking follow up questions.

Jon Hess
  • 14,237
  • 1
  • 47
  • 51