Question

I have an objc program and i would like to use a widget that is written in objc++ (namely https://launchpad.net/scintilla-cocoa). How do i go about this? Basically i want a new window controller object to interface with this objc++ library to define a scintilla text editor widget. Simply creating a new 'objc class' and accessing the library from there generates a bunch of errors related to the C++ class keyword and so on.

Thanks in advance

Was it helpful?

Solution

Since I'm the one who put you into the (hopefully rewarding :-)) trouble of using Scintilla, here I am.


Let's say we create a ScintillaView subclass, named ppScintillaEditor. The file should have an .mm extension (e.g. ppScintillaEditor.mm)

The code would be roughly like this...

Interface

#import "Scintilla/ScintillaView.h"

@interface ppScintillaEditor : ScintillaView
{
    // your iVars
}

// your properties / methods / whatever

Now, as for the implementation part, remember to put some initialization method to set up the view properly (as in the example accompanying Scintilla-cocoa; I mean the Test project)


Sidenote : Of course, you can create subclasses, categories or whatever on top the ScintillaView class, pretty much based on what you need - I, for example, have create a separate Category just in order to group there some ScintillaView specific commands (sooner or later, you'll notice that for some more advanced Scintilla manipulations, although it's there, it may need some polishing to be a bit more cocoa-friendly, so here you go...)


Now, last but not least...

To resolve the "bunch of errors related to the C++ class keyword and so on", as I've shown in my other video-response to your comment, all you have to do is :

  • Go to your project's Build Settings
  • Under Apple LLVM Compiler 3.0 - Preprocessing
  • Option Preprocessor Macros
  • Add to both Debug and Release :

    SCI_NAMESPACE SCI_LEXER
    

And that's it. :-)


Hint : The above are defined by Scintilla to avoid clashes between C and non-C elements, like above... so, all it takes is to notify the preprocessor and the rest is taken care of....

OTHER TIPS

you would create an objc class which has the interface your app needs, then implement and add the ivars and implement -- all behind a compilation firewall so the objc++ sources are not included in the header. your implementation would provide any necessary conversions.

it is like you have already done, but you remove the scintilla headers from the header for your wrapper -- they are visible only to your wrapper's implementation.

Update

To illustrate one possible approach:

MONScintillaWrapper.h

// no c++/scintilla sources should be included in this header
#import <Foundation/Foundation.h>

@interface MONScintillaWrapper : NSObject

- (void)setBackgroundColor:(NSColor *)pColor;    

@end

MONScintillaWrapper.mm

#import "MONScintillaWrapper.h"

@implementation MONScintillaWrapper
{
  scintilla::t_thing scintillaThing;
}

- (void)setBackgroundColor:(NSColor *)pColor
{
...convert pColor to a scintilla color and pass that to scintillaThing...
}

@end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top