Re: Cursor above siblings

2015-01-10 Thread ecir hana
Hi Uli,

thanks a lot for the reply!

I tried to override mouseMoved:, addCursorRect:cursor:,
cursorUpdate:, resetCursorRects, mouseEntered: without calling
super, but the I-beam cursor is still set when it is being moved over
NSTextView.

I also found this in the Cocoa Event Handling Guide docs:

Cursor-update events are a special kind of mouse-tracking event that the
 Application Kit handles automatically. When the mouse pointer enters a
 cursor rectangle, the Application Kit displays a cursor image appropriate
 to the type of view under the rectangle; for example, when a mouse pointer
 enters a text view, an I-beam cursor is displayed.


One can read the handles automatically above as no easy way to override.

I also think I read somewhere sometime that someone overrode the mouseMoved:
method for cursor setting but I cannot find it anymore.

However, I'm not sure I understood your last advice: what subview do you
mean? Both the button (or the view holding the button) and the textview are
siblings. If I make the button a subview of the textarea it wont show up at
all..?

In any case, I will try to look into this further so if anyone has an idea
about this, please let me know.


On Sat, Jan 10, 2015 at 3:09 PM, Uli Kusterer witness.of.teacht...@gmx.net
wrote:

 On 09 Jan 2015, at 14:19, ecir hana ecir.h...@gmail.com wrote:
  I have a window with a custom view, which contains two children: a
 textview
  with scrollbars and a button. I would like to overlay the button over the
  textview so when I click in that area somewhere, the button receives the
  event before the textview. It kind of works, except for one thing: the
  cursor is always of the I-beam variety, even when above the button, see
 [1]
  and [2].

  With a regular view, I would say you just need to create a cursor region
 around your button that overrides the one set by the other view to set an
 arrow, but ISTR that cursor regions that overlap have always been kind of
 unreliable. At least that’s what I’ve found in my testing so far. Sometimes
 they just don’t seem to trigger.

  Another problem seems to be that NSTextView seems to not be using cursor
 views. I have the impression that it just listens for mouseMoved events and
 re-sets the cursor every time. I still haven’t fully figured out what’s
 going on here.

  So in short, you could try to override NSTextView to see if you can get
 it to not set the cursor at all, then make it use cursor regions instead.
 If the overlapping of cursor regions doesn’t work sufficiently well, you
 could make the cursor view aware of the other views’ cursor rects and just
 have it generate a series of rects with the subviews’ rects cut out, then
 only set cursor regions for the remaining views. Maybe you’ll have to
 override mouseMoved: for that, and just not call the inherited method when
 it’s over a subview.

 Cheers,
 -- Uli Kusterer
 “The Witnesses of TeachText are everywhere...”
 http://zathras.de


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Cursor above siblings

2015-01-10 Thread ecir hana
On Sat, Jan 10, 2015 at 4:54 PM, Uli Kusterer witness.of.teacht...@gmx.net
wrote:


  I think you’re reading that into the documentation. In most views,
 cursor-setting is pretty much predictable, and I think text views are
 mainly meant as an example here, and aren’t that special.


Yeah, you are probably right...

I did the same, and one thing that looks like it turns off the cursor is
 overriding resetCursorRects and updateTrackingAreas to do nothing, and doing

 -(void) viewDidMoveToWindow
 {
 [super viewDidMoveToWindow];

 [self.enclosingScrollView setDocumentCursor: nil];
 [self.enclosingScrollView updateTrackingAreas];
 [self.enclosingScrollView resetCursorRects];
 }

 That turns off the text view’s cursor, it seems.


Well, I have the custom textview which has empty both resetCursorRects
and updateTrackingAreas, and the snippet from you above, and it still
sets the I-beam cursor. What's more, now it sometimes does not set the
cursor back to the arrow one when I leave the textview area.

I will definitely let you know, if I figure out something useful... One
idea is that I may just drop this floating above approach and do what
NSTextFinder does, namely temporary resize the enclosing scrollview and put
that button over the newly cleaned up area. I would prefer the former,
though, so I will try a bit more.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Cursor above siblings

2015-01-10 Thread ecir hana
On Sat, Jan 10, 2015 at 6:18 PM, Quincey Morris 
quinceymor...@rivergatesoftware.com wrote:


 — Make sure you *start* by investigating whether the tracking area options
 are configured correctly. You’re wasting your time if you go off looking
 for interactions between “sibling” tracking areas if in fact you just put
 the tracking area’s rect in the wrong place.


I have single one custom view and its tracking area covers the whole [self
bounds]. I set the tracking area in awakeFromNib and it works. Btw.,
Quickies for NSView has a section for Setting a cursor for a view which
works, too.

— If you can’t get it to work with the button, try ignoring the button, and
 add a custom view as a sibling of the text view. If that works, then
 perhaps the button is doing something itself that’s interfering with your
 intentions.

 — Re-arrange your view hierarchy so that the button [or your custom view]
 is still a sibling of the text view, but does not overlap it at all.
 Install a tracking area that (say) changes the pointer to a pointing
 finger, so it’s really obvious when it works right. If it doesn’t, the
 problem is nothing to do with the text field. There’s no point in going on
 to the next step until this works.


It works as expected: the custom view shows one pointer, textview the
other. They views don't overlap.


 — Then, move the button so that it partially overlaps the text field. You
 should now be able to see if there are any side-effects of crossing into
 and out of the overlap. If there are, you’ll have to do extra work to find
 a solution.


And that is where it stops working, no need to visit Neptune. The part of
custom view over the textview stops displaying the defined cursor, at shows
I-beam cursor instead.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Cursor above siblings

2015-01-09 Thread ecir hana
Hi!

I have a window with a custom view, which contains two children: a textview
with scrollbars and a button. I would like to overlay the button over the
textview so when I click in that area somewhere, the button receives the
event before the textview. It kind of works, except for one thing: the
cursor is always of the I-beam variety, even when above the button, see [1]
and [2].

I think the problem is that the sibling views overlap but don't know how
to fix it. I tried to move the button beneath the textview in hierarchy but
that doesn't work (button is not shown) and I tried to `addTrackingArea:`
but that doesn't work either (maybe I didn't do it the right way but then
again, I thought NSButton has its own tracking area).

Please, how can I make the cursor change back to the default variety when
hovering over the button? I can place the button in a custom view and work
with that view, if that helps..?

[1] http://i.stack.imgur.com/3E6AM.png
[2] http://i.stack.imgur.com/TpzoI.png
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Few questions about NSTextView

2014-12-22 Thread ecir hana
Hi!

I'm trying to work with NSTextView but in the course of my learning I
encountered several behaviors which I cannot understand why they are
happening. Please, I would greatly appreciate if someone could explain in a
few words why do they behave like they do and how to achieve the opposite
effect.

1. Suppose there is a window which has two NSTextViews in it and each of
them uses the findbar (NSTextFinder). The problem is that after closing one
findbar (finishing the finding) the cursor jumps to the other textview,
i.e. the focus does not return the textview for which the find operation
originated. For example: the textviews are side-by-side and the left one
has the focus (cursor). When I hit cmd+f, the findbar pop-up and when I
hit esc it disappears. But now the cursor jumps to the right textview. I
would have thought that it makes sense to return to the textview which I
was typing into at first. How do I achieve this?

2. Suppose there is a window with one NSTextView which contains a lot of
text so that the scrollbars show up. Now this is very weird and I'm not
sure if anyone else can confirm this but I verified it even in TextEdit:
when the vertical scrollbar is roughly in 1/4 of the height and I resize
the window, the text re-flows immediately as I drag then window border.
When the scrollbar is in 3/4 of the height, it re-flows only after
releasing the mouse button. Why? Is there a way to make it either re-flow
always continuously or never?

3. Similar situation as the second one but this one is even more weird in
my eyes. When resizing the window with lots of text, sometimes after
releasing the mouse button the cursor jumps/scrolls into middle of the
textview and sometimes it does not. I cannot see any pattern, perhaps
besides that 1/4 and 3/4 heights but even that doesn't work consistently.
My question is, is it possible to disable the centering forever? I.e., when
resizing the window, how to make the line at which the text cursor blinks
*not* scroll into the middle of textview?

I realize the situations might not be very straightforward to picture, I
can screen-capture a video or something if there is a need. My hope is that
some more experienced developers will recognize these patterns and point me
in the right direction because apparently I'm missing something obvious.

Thanks a lot in advance for any help!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSTextView and Syntax Highlighting

2014-12-19 Thread ecir hana
On Fri, Dec 19, 2014 at 6:58 PM, Quincey Morris 
quinceymor...@rivergatesoftware.com wrote:

 On Dec 19, 2014, at 05:36 , Charles Jenkins cejw...@gmail.com wrote:
 
  Could it be that even though the layout manager's temporary attributes
 are designed for purposes like syntax highlighting, folks don't actually
 use them because they don't work right during edits?

 Since temporary attributes are in fact used for (e.g.) spell checking in
 text fields, I’m certain it works if you know how, but the path of least
 resistance for us mere mortals seems to be to use regular attributes
 instead.


Maybe you haven't seen this article already, hopefully you will find it of
some use:

http://cocoadev.com/ImplementSyntaxHighlightingUsingTemporaryAttributes
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

NSRegularExpression segfault

2014-12-15 Thread ecir hana
Hi!

I recently needed to match some patterns but I encountered a problematic
situation.

Please, can anyone explain to me why does the following program
consistently segfault after 5 characters? I'm running 10.9.5...

#import Cocoa/Cocoa.h

int main () {
NSString *pattern =
@(1+)|(2+)|(3+)|(4+)|(5+)|(6+)|(7+)|(8+)|(9+)|(0+)|(a+);
NSRegularExpression *expression = [NSRegularExpression
regularExpressionWithPattern:pattern options:0 error:nil];
for (NSUInteger i = 0; i  10; i += 1) {
NSString *string = [@ stringByPaddingToLength:i withString:@a
startingAtIndex:0];
NSTextCheckingResult *result = [expression
firstMatchInString:string options:0 range:NSMakeRange(0, i)];
NSLog(@%@, NSStringFromRange([result range]));
}
return 0;
}

It says:

{0, 0}
{0, 1}
{0, 2}
{0, 3}
{0, 4}
{0, 5}
Segmentation fault: 11

Thanks in advance!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSRegularExpression segfault

2014-12-15 Thread ecir hana
On Mon, Dec 15, 2014 at 5:44 PM, Jens Alfke j...@mooseyard.com wrote:


 What's the backtrace? Whenever investigating a crash you should always
 start by looking at the stack. (To get this in a text form you can paste
 into a message, use the debugger command bt.)


I don't seem to have bt but I got instead from Problem Report window:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libicucore.A.dylib0x7fff8f301ac1 utext_clone + 22
1   libicucore.A.dylib0x7fff8f302570
icu::RegexMatcher::reset(UText*) + 54
2   libicucore.A.dylib0x7fff8f305f01 uregex_setText + 223
3   com.apple.Foundation  0x7fff8aba343f
-[NSRegularExpression(NSMatching)
enumerateMatchesInString:options:range:usingBlock:] + 938
4   com.apple.Foundation  0x7fff8ac13ba4
-[NSRegularExpression(NSMatching) firstMatchInString:options:range:] + 145
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSRegularExpression segfault

2014-12-15 Thread ecir hana
On Mon, Dec 15, 2014 at 6:09 PM, Stephen J. Butler stephen.but...@gmail.com
 wrote:

 If you read the ICU docs on regular expressions you'll see that it sets an
 8MB limit on head size when evaluating. My guess is that you've run into
 this and NSRegularExpression misses a return code somewhere.


I would have thought 50 000 characters is not that much. But then again, I
don't really know how ICU works... Reading the ICU docs further, there it
says:

Because ICU does not use program recursion to maintain its backtracking
 state, stack usage during matching operations is minimal, and does not
 increase with complex patterns or large amounts of backtracking state.



 But your pattern is really suboptimal for what you're trying to accomplish.


It's really a reduced test case.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSRegularExpression segfault

2014-12-15 Thread ecir hana
On Mon, Dec 15, 2014 at 6:50 PM, Stephen J. Butler stephen.but...@gmail.com
 wrote:

 It seems to be related to the number of capture groups you have. For
 example, this also succeeds for me:


 ((?:1+)|(?:2+)|(?:3+)|(?:4+)|(?:5+)|(?:6+)|(?:7+)|(?:8+)|(?:9+)|(?:0+)|(?:a+))

 Do you really need the 11 capture groups?


Thanks for giving it a try!

It's not precisely 11, but yes, I need to have many. I also discovered it
is related to the number of capture groups and their complexity. One
single group works for much longer inputs but I guess you already know that.

To put it differently, even if I could reduce the number of groups a bit, I
think I will still hit that segfault for some non-trivial inputs. For
example, when I only use 6 groups it still segfaults at around 80 000
characters.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSRegularExpression segfault

2014-12-15 Thread ecir hana
On Mon, Dec 15, 2014 at 6:59 PM, ecir hana ecir.h...@gmail.com wrote:

 It's not precisely 11, but yes, I need to have many.


By many I mean more than 2 and less than...maybe 10.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSRegularExpression segfault

2014-12-15 Thread ecir hana
On Mon, Dec 15, 2014 at 8:04 PM, Jens Alfke j...@mooseyard.com wrote:


 Anyway, please file a bug report with Apple, as this seems to be a bug in
 NSRegularExpression.


Done!

I'm no expert on regular expressions, but my understanding is that all the
 implementations have a couple of pathological conditions where for certain
 expressions the memory usage goes up rapidly with input length, and if you
 run into one of those you'll need to adjust your expression to work around
 it.


I'm also no expert on regexps but I thought that the pathological
conditions are met when using back-references (which I don't use). In any
case, I tried it in JavaScript and it works up to 10 000 000 characters (I
didn't try more).

var pattern = /(1+)|(2+)|(3+)|(4+)|(5+)|(6+)|(7+)|(8+)|(9+)|(0+)|(a+)/;
var result = pattern.exec(new Array(1001).join(a));
console.log(result.index, result[0].length);

Thanks again for all the replies!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Size of NSSplitViewDividerStyleThin

2014-12-11 Thread ecir hana
Thanks for the reply!

You are right that `splitView:additionalEffectiveRectOfDividerAtIndex:`
looks better. I tried id but it still exhibits the said behavior.

But I noticed that the grab area is indeed wider than 1px (perhaps it is
even 5px!) but the mouse cursor does not turn into `resizeUpDownCursor` (?)
when hovering above the divider. Hence it is very confusing why would one
want to grab the divider when the cursor is the default text selection one.

Btw., when I don't do `setDocumentView` for the textviews, the cursor shows
up as expected.

Why is this happening? Is it possible to have the resizing cursor over the
whole divider frame?

This is the code I'm using: http://pastebin.com/ZnW8LWyT



On Thu, Dec 11, 2014 at 5:35 AM, Quincey Morris 
quinceymor...@rivergatesoftware.com wrote:

 On Dec 10, 2014, at 17:54 , ecir hana ecir.h...@gmail.com wrote:


 My question is, how to have a thin divider which has wider hit area than
 1px? In other words, I like how `NSSplitViewDividerStyleThin` looks and how
 `NSSplitViewDividerStyleThick` behaves. Is it somehow possible to have
 both?


 This doesn’t sound right. According to the NSScrollViewDelegate
 documentation:

 A split view with thin dividers proposes an effective frame that's a
 little larger than the drawn frame, to make it easier for the user to
 actually grab the divider.”


 And AFAICT this is what actually happens in (say) Mail, where the mail
 list appears to be just a table view in a scroll view. I get more than 1
 pixel’s leeway to grab the dividers on each side of it.

 Anyway, ‘splitView:additionalEffectiveRectOfDividerAtIndex:’ isn’t
 intended for widening the grab region. It’s for adding a separate rect
 containing (e.g.) a grabber icon, that’s below or to one side of the
 divider. The delegate method
 ‘splitView:effectiveRect:forDrawnRect:ofDividerAtIndex:’ appears to be
 intended for what you want to do.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Size of NSSplitViewDividerStyleThin

2014-12-11 Thread ecir hana
Thanks for the reply again! The problem is I now tried to only copy-paste
from the Apple docs and Cocoa with Love and I still get the said behavior.
That is, when I move the mouse cursor slowly across the divider it changes
back to text selection cursor right after leaving the splitting line. In
picture:

 |
 |
-X--- -- divider
 X
 X -- resize cursor
 | -- text selection cursor
 |

 ^ moving mouse from here in the upper direction

Why does not the cursor continue to be of the resize variety for the
additional 2 pixels?

I pastebin'ed a sample code here: http://pastebin.com/RBJXMBqh , if you or
someone else want to try this. Just paste the code into Terminal...

PS: Perhaps even more importantly, does anyone else sees this kind of
behavior at all?






On Thu, Dec 11, 2014 at 8:49 PM, Quincey Morris 
quinceymor...@rivergatesoftware.com wrote:

 On Dec 11, 2014, at 02:56 , ecir hana ecir.h...@gmail.com wrote:


 Btw., when I don't do `setDocumentView` for the textviews, the cursor
 shows up as expected.

 Why is this happening? Is it possible to have the resizing cursor over the
 whole divider frame?


 My guess is that there’s something wrong with the resizing of your text
 views to fit the scroll view’s container, so near the divider the cursor is
 over a text view *and* the divider cursor (i.e. grab) rect, and the text
 view is winning control of the cursor.

 Possibly your text views are not resizing with the window at all, or
 possibly they’re resizing but their edges are pinned slightly outside the
 scroll view’s visible rect.

 Yet another issue might be the text view’s own insets, which typically
 provide clearance between the view’s container and the actual text. I
 believe the default is for some clearance on the sides and maybe the top,
 but I’m not sure about the bottom.

 Either way, since the “extra pixels each side of the divider that help to
 grab it” aren’t part of a divider “view”, I think you’ll have to make sure
 that the content of the split pane stay far enough away from the divider’s
 physical thickness to permit this whole “extra pixels” thing to work.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Size of NSSplitViewDividerStyleThin

2014-12-10 Thread ecir hana
Hi,

I have two NSTextViews, each of which is wrapped in NSScrollView and both
are embedded inside NSSplitView:

+--+
|++|
||+--+||
|||  | NSTextView
||+--+||
|++|
+--+-- divider
|++|
||+--+||
|||  || NSScrollView
||+--+||
|++|--- NSSplitView
+--+

I think all the pieces have fairly default settings, in particular, the
divider has `NSSplitViewDividerStyleThick` `dividerStyle`. And everything
works fine.

The problem begins when I set the style to `NSSplitViewDividerStyleThin`.
The gap (grab area) between the two textviews becomes 1px wide and it
becomes very diffult to grab the divider and alter the splitting. I tried
to add `splitView:additionalEffectiveRectOfDividerAtIndex:` to the
delegate, and it even adds the extra rectangle, but it still doesn't work
becase the rectangle becomes covered up by the textviews(?). I mean, it is
there but I cannot grab it because it is beneath the textviews, so it still
effectively is 1px wide.

My question is, how to have a thin divider which has wider hit area than
1px? In other words, I like how `NSSplitViewDividerStyleThin` looks and how
`NSSplitViewDividerStyleThick` behaves. Is it somehow possible to have both?

Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Dynamic library linking

2013-02-24 Thread ecir hana
Hello,

I have a simple program which I can compile but when I tried to link it
with a dynamic library the linker is not able to find the library, despite
that it is in the same folder as the program.

The longer version: I want to embed Python 3.3 interpreter into simple C
program. I'm on MacOS 10.8, which ships with Python 2.7. I downloaded the
binary distribution of 3.3 version from python.org, copied the dynamic
library from the bundle to a folder, along with all the headers. The
library I copied was a file named Python which had a symlink pointing to
it named libpython3.3m.dylib. Now that the library is in the folder,  I
renamed it to python33 so it wouldn't collide with installed Python of
version 2.7.

So the folder has these files: embed.c, python33 and include folder.
The embed.c containts:

#include Python.h

int
main(int argc, char *argv[])
{
  Py_Initialize();
  PyRun_SimpleString(print 'test'\n);
  Py_Finalize();
  return 0;
}

and running file python33 says:

python33 (for architecture i386): Mach-O dynamically linked shared
library i386
python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
shared library x86_64

The problem I have is that when try to run:

gcc embed.c -I./include -L. -lpython33

if breaks with:

ld: library not found for -lpython33

Please, does anyone know why?

I guess this is not exactly Cocoa-related question but I tried to ask about
this at various places and I have not found a solution, yet.

I have various theories about why this happens, I would be thankful if
someone could confirm/reject these:

- I cannot just copy out a dynamic library out of a bundle, I have to
install the whole Python 3.3 and after it is properly installed at
particular locations, then I can link with it.

- I'm missing some linker flags. I tried DYLD_LIBRARY_PATH=. but it
didn't help.

- The Python 3.3 library was compiled with different compiler that what I
use to compile my program with.

PS: it compiles with:

gcc embed.c -I./include python33

but when I tun ./a.out it breaks with:

dyld: Library not loaded:
/Library/Frameworks/Python.framework/Versions/3.3/Python
Referenced from: /Users/ecir/Desktop/embed/./a.out
Reason: image not found
Trace/BPT trap: 5

I would really appreciate any hint on how to solve this, thank you in
advace!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dynamic library linking

2013-02-24 Thread ecir hana
Ken Thomases, Ben Kennedy,

thanks for the replies!

Yes, I tried libpython33.so, libpython33.dylib, python33.dylib, ...

But I still get that error, even if the file is ls -al:

-r-xr-xr-x@   1 ecir  staff  5503912 29 sep 10:27 libpython33.so

That -v switch is a good advice but I cannot really make any sense of
this http://pastebin.com/ugWxEWw8


On Sun, Feb 24, 2013 at 9:51 PM, Ken Thomases k...@codeweavers.com wrote:

 On Feb 24, 2013, at 2:09 PM, ecir hana wrote:

  and running file python33 says:
 
 python33 (for architecture i386): Mach-O dynamically linked shared
  library i386
 python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
  shared library x86_64
 
  The problem I have is that when try to run:
 
 gcc embed.c -I./include -L. -lpython33
 
  if breaks with:
 
 ld: library not found for -lpython33
 
  Please, does anyone know why?

 The -l option expects a file with the prefix lib and a library suffix.
  So, -lpython33 requires that the file be named libpython33.something
 (where something might be dylib or a or possibly a couple of other things).

 When you have issues like this, you might try passing -v for verbose
 output.  It would probably tell you precisely which file names it tried.

 Regards,
 Ken


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dynamic library linking

2013-02-24 Thread ecir hana
Marco S Hyman, Stephen J. Butler,

thanks a lot! Indeed, stupid me, I was missing -L.. I used to use it (as
I copy-pasted above) but somehow when hitting up arrow in terminal I must
have accidentally deleted it. Now it links! So to recap, properly naming
the library (libpython33.so) and compiling with:

gcc embed.c -I./include -L. -lpython33

works! Thank you so much people!

The problem is, as Stephen points out, the executable doesn't run:

Reason: image not found
Trace/BPT trap: 5

I will read the links about frameworks now...


On Sun, Feb 24, 2013 at 10:20 PM, Stephen J. Butler 
stephen.but...@gmail.com wrote:

 This is an advanced topic which touches on a lot of OS X details. The
 short of it is, even if you solve your linking problems your Python 3.3
 library won't work.

 What you need to is include the entire Python 3.3 framework in your
 Application bundle. Once you've figured out how to do that, linking against
 it is as simple as telling Xcode to link the framework. Here are two links
 some Googling brought up:

 Here's the official docs:


 https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

 Look under Embedding a Private Framework in Your Application Bundle and
 start following links. This StackOverflow question touches on the subject:


 http://stackoverflow.com/questions/1621451/bundle-framework-with-application-in-xcode



 On Sun, Feb 24, 2013 at 2:09 PM, ecir hana ecir.h...@gmail.com wrote:

 Hello,

 I have a simple program which I can compile but when I tried to link it
 with a dynamic library the linker is not able to find the library, despite
 that it is in the same folder as the program.

 The longer version: I want to embed Python 3.3 interpreter into simple C
 program. I'm on MacOS 10.8, which ships with Python 2.7. I downloaded the
 binary distribution of 3.3 version from python.org, copied the dynamic
 library from the bundle to a folder, along with all the headers. The
 library I copied was a file named Python which had a symlink pointing to
 it named libpython3.3m.dylib. Now that the library is in the folder,  I
 renamed it to python33 so it wouldn't collide with installed Python of
 version 2.7.

 So the folder has these files: embed.c, python33 and include folder.
 The embed.c containts:

 #include Python.h

 int
 main(int argc, char *argv[])
 {
   Py_Initialize();
   PyRun_SimpleString(print 'test'\n);
   Py_Finalize();
   return 0;
 }

 and running file python33 says:

 python33 (for architecture i386): Mach-O dynamically linked shared
 library i386
 python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
 shared library x86_64

 The problem I have is that when try to run:

 gcc embed.c -I./include -L. -lpython33

 if breaks with:

 ld: library not found for -lpython33

 Please, does anyone know why?

 I guess this is not exactly Cocoa-related question but I tried to ask
 about
 this at various places and I have not found a solution, yet.

 I have various theories about why this happens, I would be thankful if
 someone could confirm/reject these:

 - I cannot just copy out a dynamic library out of a bundle, I have to
 install the whole Python 3.3 and after it is properly installed at
 particular locations, then I can link with it.

 - I'm missing some linker flags. I tried DYLD_LIBRARY_PATH=. but it
 didn't help.

 - The Python 3.3 library was compiled with different compiler that what I
 use to compile my program with.

 PS: it compiles with:

 gcc embed.c -I./include python33

 but when I tun ./a.out it breaks with:

 dyld: Library not loaded:
 /Library/Frameworks/Python.framework/Versions/3.3/Python
 Referenced from: /Users/ecir/Desktop/embed/./a.out
 Reason: image not found
 Trace/BPT trap: 5

 I would really appreciate any hint on how to solve this, thank you in
 advace!
 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:

 https://lists.apple.com/mailman/options/cocoa-dev/stephen.butler%40gmail.com

 This email sent to stephen.but...@gmail.com



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Open untitled file in Document-based app

2012-10-24 Thread ecir hana
On Tue, Oct 23, 2012 at 11:58 PM, Graham Cox graham@bigpond.com wrote:


 If you return YES from -applicationOpenUntitledFile: the application will
 NOT open a new file - it has assumed that this method has done it and by
 returning YES that's what you're telling it. You want to either return NO
 or else not override this method at all.


Thanks for the reply!

I tried both to return NO and  to not overriding the method but it still
wont open any window at start up. The method(s) are not even called..? I
think it has something to do with 10.8 restoring the previous state but I'm
not sure how to force it to open an window if there was no window at
application exit.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Open untitled file in Document-based app

2012-10-24 Thread ecir hana
On Wed, Oct 24, 2012 at 7:13 PM, Sean McBride s...@rogue-research.comwrote:


 That restoring state stuff is new in 10.7, not 10.8.  You can test if it
 is responsible by turning it off in System Preferences  General.


Yes, it is! When I turn it off (Close windows when quitting an application)
it works as before. Is it possible to have the same behavior even when a
user has the restoring state stuff enabled?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Open untitled file in Document-based app

2012-10-23 Thread ecir hana
Hello,

I would like my app to open new untitled document every time it starts. It
worked in 10.6 but now I upgraded to 10.8 and when I close the window with
cmd+w and then restart the application it wont open any windows.

Please, how to make it open a new window every time the app starts,
regardless of how it exited previously?

I tried to return YES in both applicationShouldOpenUntitledFile: and
applicationOpenUntitledFile: of the app delegate without luck.

Thanks in advance!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTextView paste:

2012-08-15 Thread ecir hana
On Tue, Aug 14, 2012 at 2:43 AM, Seth Willits sli...@araelium.com wrote:


 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard type:(NSString
 *)type
 {
 if ([type isEqual:NSStringPboardType]) {
 if ([[pboard stringForType:type] isEqual:@foo]) {
 NSRange range = [self selectedRange];

 if ([self shouldChangeTextInRange:range
 replacementString:@bar]) {
 [self replaceCharactersInRange:range
 withString:@bar];
 }

 return YES;
 }
 }

 return [super readSelectionFromPasteboard:pboard type:type];
 }


This works great, thanks a lot!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSTextView paste:

2012-08-13 Thread ecir hana
Dear list,

I have a NSTextView, where the user can paste plain text into.

When the users has foo in the pasteboard I would like bar to be pasted.
In other words, a user goes to, say, a web browser, selects foo, cmd+c,
switches to my NSTextView, cmd+v and bar appears at insertion point.

Please, does anyone know how to approach this?

I thought about subclassing readSelectionFromPasteboard:type: but what to
do then? Or is there better way of doing this?

Thanks in advance!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTextView paste:

2012-08-13 Thread ecir hana
On Mon, Aug 13, 2012 at 11:45 PM, Seth Willits sli...@araelium.com wrote:



 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard type:(NSString
 *)type
 {
 if ([type isEqual:NSStringPboardType]) {
 if ([[pboard stringForType:type] isEqual:@foo]) {
 [self insertText:@bar];
 return YES;
 }
 }

 return [super readSelectionFromPasteboard:pboard type:type];
 }


Thank you for the reply! Unfortunately, there seem to be a tiny bug with
undo. My textview has setRichText: set to NO so that it triggers
the first condition. When the textview looks like this:

aaa
bbb

and I select and copy aaa, then select bbb, delete it by hitting --,
paste aaa, and then I try to undo, it does nothing, i.e. the last line
remains bbb, instead of . In menubar, there it even says Undo Paste
but it does nothing.

Any idea would that could be?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTextView paste:

2012-08-13 Thread ecir hana
On Tue, Aug 14, 2012 at 12:55 AM, ecir hana ecir.h...@gmail.com wrote:




 aaa
 bbb


 I mean:

foo
foo
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTextView scrolling

2012-07-31 Thread ecir hana
On Tue, Jul 31, 2012 at 6:19 AM, Richard Somers rsomers...@awinets.comwrote:


 This might help.


 http://www.cocoabuilder.com/archive/cocoa/145464-nstextview-auto-scroll-up-behaviour.html


Thanks for the reply! However, it does not seem to work - it still scrolls
half-page up/down, even if I change the margin variable there...

[sorry for the previous mail - it has a typo]
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSTextView scrolling

2012-07-30 Thread ecir hana
Hello,

when jumping from line to line in a textview with up and down keys, it
exhibits this scrolling behavior - when the cursor is at the very top and I
hit up (and vice versa), it scrolls the document half page up, that is,
the current line is now in the middle of the textview.

Is it possible to disable this behavior? Is it possible to make it scroll
by just one line? So that the current line stays always at the top (bottom)?

Thanks in advance,

Ecir Hana
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Getting NSApplicationDelegate protocol

2012-07-07 Thread ecir hana
On Sat, Jul 7, 2012 at 6:30 AM, Ken Thomases k...@codeweavers.com wrote:

 
  Thank you. And please, can you explain to me why is it that case? Is it
 simply because AppKit includes the definition of NSTextViewDelegate
 protocol and not includes one for NSApplicationDelegate?

 Correct.

  Is it somewhere documented which protocols are not included?

 I doubt it.  It's not that anybody made a conscious decision to omit
 NSApplicationDelegate.  It's just a consequence of how the code was written
 and what the compiler and linker do.

  I mean, besides NSApplicationDelegate, what other delegate definitions
 cannot be obtained at runtime?

 Who knows.  It depends entirely on what the AppKit code used and what the
 compiler and linker did with that.

  Or is there anything like AppKit which, after being loaded, provides the
 definitions?

 Anything which referenced them in the described manner (includes a class
 which adopted them or code which references them via @protocol()).


Thank you so much for the explanation!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Getting NSApplicationDelegate protocol

2012-07-06 Thread ecir hana
Hello,

I'm trying to get the methods a protocol specifies and just stumbled upon
one problem: the following code returns NULL:

Protocol *protocol = objc_getProtocol(NSApplicationDelegate);

I saw (
http://stackoverflow.com/questions/10212119/objc-getprotocol-returns-null-for-nsapplicationdelegate)
that the it is because the protocol was not:

Adopted by a class,
Or referred to somewhere in source code (using @protocol())

As am doing this at runtime, I cannot use @protocol(), right?

So I thought I will add the protocol to the class:

Protocol *protocol = objc_getProtocol(NSApplicationDelegate);
BOOL class_addProtocol(class, protocol);

The problem, obviously, is that I cannot add a protocol until it been
created and the protocol wont be created until used be a class.

Is there a way to get NSApplicationDelegate protocol besides the
compile-time @protocol()?

Also, when I do:

Protocol *protocol = objc_getProtocol(NSTextViewDelegate);

return the protocol even when I didn't create any textviews...?

PS: To get all the method descriptions of a protocol, do I have to call
four times protocol_getMethodDescription?

protocol_getMethodDescription(p, aSel, NO, NO);
protocol_getMethodDescription(p, aSel, NO, YES);
protocol_getMethodDescription(p, aSel, YES, NO);
protocol_getMethodDescription(p, aSel, YES, YES);
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Getting NSApplicationDelegate protocol

2012-07-06 Thread ecir hana
Sorry I should've said that before: no, I'm on 10.6.

But thanks for the reply!

On Fri, Jul 6, 2012 at 11:14 AM, Stephen J. Butler stephen.but...@gmail.com
 wrote:

 On Fri, Jul 6, 2012 at 3:30 AM, ecir hana ecir.h...@gmail.com wrote:
  I'm trying to get the methods a protocol specifies and just stumbled upon
  one problem: the following code returns NULL:
 
  Protocol *protocol = objc_getProtocol(NSApplicationDelegate);

 Are you trying this on 10.5? Or are you building this application with
 the 10.5 SDK?

 Before 10.6 the NSApplicationDelegate was an informal protocol (that
 is, a category of methods on NSObject). This is because @optional
 didn't appear till the 10.6 SDK/compiler and previous to that for
 protocols:

 1) all methods were mandatory
 2) you couldn't extend the protocol later; once you publish it's set
 of methods in a Framework you were fixed at that set

 Point (2) follows from point (1) if you think about it enough.

 So some of the protocols, like NSApplicationDelegate, weren't really
 protocols at all. But in 10.6 they introduced @optional, and
 NSApplicationDelegate became a formal protocol.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Getting NSApplicationDelegate protocol

2012-07-06 Thread ecir hana
On Fri, Jul 6, 2012 at 11:56 AM, Ken Thomases k...@codeweavers.com wrote:

  Is there a way to get NSApplicationDelegate protocol besides the
  compile-time @protocol()?

 No.  The run-time information about the protocol is obtained from
 information that would have to have been baked into the executable at build
 time.


  Also, when I do:
 
 Protocol *protocol = objc_getProtocol(NSTextViewDelegate);
 
  return the protocol even when I didn't create any textviews...?

 You have presumably loaded AppKit, and AppKit does have the protocol
 details for NSTextViewDelegate baked into it, because it includes classes
 which adopt it and/or code which uses @protocol(NSTextViewDelegate).


Thank you. And please, can you explain to me why is it that case? Is it
simply because AppKit includes the definition of NSTextViewDelegate
protocol and not includes one for NSApplicationDelegate? Is it somewhere
documented which protocols are not included? I mean,
besides NSApplicationDelegate, what other delegate definitions cannot be
obtained at runtime? Or is there anything like AppKit which, after being
loaded, provides the definitions?

And for the ones includes, how to get all the methods described?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Getting NSApplicationDelegate protocol

2012-07-06 Thread ecir hana
On Fri, Jul 6, 2012 at 8:01 PM, Stephen J. Butler
stephen.but...@gmail.comwrote:


 You're positive you're linking against the 10.6 SDK? Even if you're on
 10.6 you might be linking against the 10.5 SDK and that would explain
 your problem perfectly.


NSAppKitVersionNumber says 1038.36 which is 10.6.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Findbar highlighting

2012-06-18 Thread ecir hana
Hello,

Since Lion NSTextView has this very nice feature - when searching for a
text as a user it also highlights all the occurrences of given search
string.

Is it possible to programmatically force triggering the highlighting? In
other words, is it possible to re-use the functionality to highlight some
string, without actually using the findbar?

Have a nice day,

Ecir Hana
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTextView

2012-06-07 Thread ecir hana
On Thu, Jun 7, 2012 at 5:47 AM, koko k...@highrolls.net wrote:

 On an NSTextView I call -selectAll: and then -insertText:

 This scrolls the view to the end of the text.

 How would I scroll the view to the top of the text?


Just before the insertText: get the current scroll position and then
restore it:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/Scrolling.html
Determining the Current Scroll Location
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSTextView selection

2012-06-04 Thread ecir hana
Hello,

I have a NSTextView and when I select all the text, all the lines get
highlighted from left to right margin, except the last line which is
highlighted from left margin to the last character on line. Please, is it
possible to highlight the last line in the same way as the other ones are,
i.e. to highlight it from left to very right?

I think I need to use setExtraLineFragmentRect:usedRect:textContainer: of
NSLayoutManager but I'm not sure how to proceed and if it's even the right
way of doing this.

Thanks in advance,

Ecir Hana
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Censoring pasted text

2012-05-25 Thread ecir hana
Hello,

if I paste some text from clipboard into a textview, is there a way to
replace all the occurrences of foo by bar? If possible, I don't want to
use textStorageDidProcessEditing: as it is called every time I type in
something. To put it in other words, is there perhaps an event which is
fired when I paste in something? Is it possible to differentiate between
text change coming from typing or pasting?

Thanks in advance!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSTextView row number

2012-05-22 Thread ecir hana
Hello,

I have a NSTextView and would like to keep track of where the cursor is in
terms of a line number. Please, is there a way to figure this out somehow
(akin ti lineRangeForRange:) or do I have to calculate it myself, e.g. by
caching newlines locations?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: saveDocument:

2012-05-10 Thread ecir hana
On Thu, May 10, 2012 at 2:24 AM, Graham Cox graham@bigpond.com wrote:


 If you build a document-based app using Xcode's template, it will work
 correctly from the very first time you run it. Then you can see how it's
 put together, and all of these things will slowly become obvious.


I'm doing precisely this. I run two projects in parallel, one by Xcode, one
by hand and compare the findings. The problem I have right now is that the
one from Xcode just works and I don't know why, it seems to do lots of
things under the hood. For instance, MyDocument.m does not even have to
have dataOfType:error: or readFromData:ofType:error: in order to show Save
as enabled in the menu. On the other hand, yes, that's something I totally
did not anticipate so I guess I learned something new.


 At the very least if you insist on this approach, you should read all of
 the documentation thoroughly, so you understand the (many) concepts that
 lie behind Cocoa's architecture.


I'm reading, really.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: saveDocument:

2012-05-10 Thread ecir hana
On Wed, May 9, 2012 at 5:40 PM, Quincey Morris 
quinceymor...@rivergatesoftware.com wrote:

 Very occasionally, it's necessary to subclass the NSDocumentController and
 force the singleton to your own subclass, but this is rare.


This is what I try to do - subclass the
NSDocumentController in applicationWillFinishLaunching:.


Thus, for example, the 'saveDocument:' action will be normally be delivered
 to the NSDocument-subclass object directly, because it is in the responder
 chain that's active when the menu item is chosen. Note that NSDocument
 *has* a 'saveDocument:' method; NSDocumentController doesn't.


Ok. My NSDocument has saveDocument:, and my NSDocumentController doesn't
have it. But the menu has Save as disabled.

Thanks for the links, there is also:

http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.html
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: saveDocument:

2012-05-10 Thread ecir hana
It works now! The problem was, that I was creating the window manager with
init:, instead of the initializers from the docs.

Thank you all for the replies, they were very helpful!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Window cascading

2012-05-09 Thread ecir hana
On Wed, May 9, 2012 at 5:08 AM, Peter Ammon pam...@apple.com wrote:


 Hope that helps,


It did. Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: saveDocument:

2012-05-09 Thread ecir hana
On Tue, May 8, 2012 at 6:33 PM, Fritz Anderson fri...@manoverboard.orgwrote:


 I'll get this wrong if I answer in the amount of time I have. Look up
 responder chain in the Mac OS X documentation.

 To oversimplify:

 Menu commands typically go to the first responder — whatever has the UI
 focus. If the focused object doesn't implement the menu item's method, the
 event system shops the event up a logical hierarchy called the responder
 chain (e.g. text field - window - document - application) until it
 finds an object that does implement the command. The first object that
 implements the command executes it.

 File  Save Document sends saveDocument: to the first responder. Because
 the chain goes from bottom up, the saveDocument: message arrives at the
 document object directly, without mediation from the application's document
 controller.


Thanks.

I apologize but I still don't quite understand. If I just
implement saveDocument: at the document and leave document controller
without it, the menu item is still disabled. When I add saveDocument: to
the controller as well, it works. I mean, if I try to visualize it, if I
just alloc:init: a document it just floats there in memory, how would a
menu know about it? So I need to create it via the document controller, no?
If this is the case, how to propagate the saveDocument: event though
the document controller to the document?

To put it differently, you seems to be saying that that the responder chain
flows the other way than what I thought. Ok, but then how does it know
about the document? When I were doing this in Xcode, I would just connect
the menu item to the first responder and the document from IB would receive
the saveDocument:, right? But there has to be a document controller, I
imagine it is somehow implied or implicit as in not exposed to the
user, which does the heavy lifting, do I understand this correctly? If so,
what exactly does this document controller do?

I'm sorry for such basic questions I'm very new to all this.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Window cascading

2012-05-08 Thread ecir hana
Hello,

I create a window like this:

id window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200,
200) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered
defer:NO] autorelease];
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];

but it cascades just vertically - the next window is positioned to the very
top left of my screen, the next one is just 20px lower (and 0px right), the
next one is again 20px lower than the previous one but it wont move
horizontally.

Why's that? Do I have to remember the returned NSPoint and pass it to
next cascadeTopLeftFromPoint:?

Kind regards,

Ecir Hana
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Window cascading

2012-05-08 Thread ecir hana
Thank you for the reply!

Yes, document-based.

However, not sure if it is an issue, but I have my own subclassed window
controller. The docs also say that the default for shouldCascadeWindows
is YES. I tried to set it to YES in setShouldCascadeWindows:, without
luck.

I look at the EnhancedDataBurn example but it uses the origin of already
shown window, which is slightly different than my case, I believe.



On Tue, May 8, 2012 at 4:35 PM, Richard Somers rsomers...@awinets.comwrote:

 On May 8, 2012, at 3:01 AM, ecir hana wrote:

  I create a window like this:
 
  id window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200,
  200) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered
  defer:NO] autorelease];
  [window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
 
  but it cascades just vertically - the next window is positioned to the
 very
  top left of my screen, the next one is just 20px lower (and 0px right),
 the
  next one is again 20px lower than the previous one but it wont move
  horizontally.
 
  Why's that? Do I have to remember the returned NSPoint and pass it to
  next cascadeTopLeftFromPoint:?

 If I remember correctly you are using the document architecture. The
 documentation has this to say.

 If you use the Cocoa document architecture, you can use the
 setShouldCascadeWindows: method of NSWindowController to set whether the
 window, when it is displayed, should cascade in relation to other document
 windows (that is, have a slightly offset location so that the title bars of
 previously displayed windows are still visible). The default is true, so
 typically you have no additional work to perform.

 If you are not using the document architecture, you can use the
 cascadeTopLeftFromPoint: method ofNSWindow to cascade windows yourself. The
 method returns a point shifted from the top-left corner of the window that
 can be passed to a subsequent invocation of cascadeTopLeftFromPoint: to
 position the next window so the title bars of both windows are fully
 visible.


 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/WinPanel/Tasks/SizingPlacingWindows.html

 Have you examined the EnhancedDataBurn sample code? It has two examples of
 where -[NSWindow cascadeTopLeftFromPoint:] is used.


 http://developer.apple.com/library/mac/#samplecode/EnhancedDataBurn/Introduction/Intro.html

 --Richard


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Window cascading

2012-05-08 Thread ecir hana
Thanks! Will look at it.

On Tue, May 8, 2012 at 5:22 PM, Richard Somers rsomers...@awinets.comwrote:

 On May 8, 2012, at 8:51 AM, ecir hana wrote:

  Yes, document-based.
 
  However, not sure if it is an issue, but I have my own subclassed window
 controller. The docs also say that the default for shouldCascadeWindows
 is YES. I tried to set it to YES in setShouldCascadeWindows:, without
 luck.
 
  I look at the EnhancedDataBurn example but it uses the origin of already
 shown window, which is slightly different than my case, I believe.

 I would suggest that you download the solutions for Cocoa Programming For
 Mac OS X (3rd Edition) and look at Chapter 10_Archiving. This chapter
 contains a modern fully functional document based sample application with
 window cascading working perfectly. You should be able to quickly get the
 sample project up and running in a few minutes in Xcode 4.2 by validating
 the project build settings and setting the default SDK.

 http://www.bignerdranch.com/book/cocoa_programming_for_mac_os_x_rd_edition_

 Subclassing the window controller is a more advanced topic and if I were
 you I would not focus on that right now.

 --Richard


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


saveDocument:

2012-05-08 Thread ecir hana
Hello,

please, could you clarify one thing for me? In document-based apps, if I
were to implement my own document controller, how would I trigger the
saving of a file? In other words, in menu there is an item which fires
saveDocument: and in document there is a method saveDocument: - how
does the action travels through document controller? In yet another words:

(Menu) saveDocument: - (Document controller) ? - (Document) saveDocument:

Do I have the picture right? Is it ok to write something like (in the
controller):

- (void)saveDocument:(id)sender {
[[self currentDocument] saveDocument:sender];
}

I think I just need to pass saveDocument: from the menu to the document,
am I right?

Kind regards,

Ecir Hana
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Minimal document-based app

2012-05-07 Thread ecir hana
Thank you all very much, it is much clearer to me now. I'm diving into
documentation now...
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Minimal document-based app

2012-05-02 Thread ecir hana
Thank you all for the replies!

As I said above, I don't want the question to be whether I should better
use NIBs, or whether Cocoa is more suitable than assembler. I somewhat know
already what the role of NIB is, that it can save time and so on. What I
would like to know is what to do if I was not using NIBs, i.e. if I wanted
to build as much as possible by hand.

To put it in other words, imagine I wanted to go to some city and was
asking about the best spots for hitchhiking. I know it's faster to get
there by a car and that I can use a train. And please, let's not argue
whether I should be hitchhiking in the first place.

Now, I have some code to share!

Please, I think I managed to write an app which seems to be working but I
would like to check whether I missed something. Here what I did:

- I have to use a bundle. That is, a folder with the following structure:
Contents
Contents/Info.plist
Contents/MasOS/executable

- Info.plist has to have:
CFBundleExecutable for executable
CFBundleName for the name of top-most folder (i.e. the bundle filename)
CFBundleDocumentTypes - which I don't yet understand and will get do it
bellow

- then, the other interesting thing I found out is that I don't need to
write AppDelegate (!). So, my main.m looks like:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSApplication * application = [NSApplication sharedApplication];
a menu item which fires newDocument:
[application run];

- then, and this is the interesting bit, newDocument: gets automatically
routed to my NSDocumentClass from Info.plist and there I create the window,
the model, etc.:
- (id)init
{
   self = [super init];
   if (self) {
   NSRect contentSize = NSMakeRect(0.0f, 0.0f, 480.0f, 320.0f);
   window = [[NSWindow alloc] initWithContentRect:contentSize
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:YES];
   ...
   [window makeKeyAndOrderFront:self];
   }
   return self;
}

And when I hit apple-n, the new window pops-up! I also have to implement
dataOfType: and readFromData: - that comes next.

But I have lots of questions:

- I saw that Xcode named the Info.plist differently (it prepends my project
name to it) - is it ok just to call it Info.plist? Is there any convention?

- this CFBundleDocumentTypes - what if I wanted to have only one kind of
documents? Does it have to be an array as well? What is the absolute
minimum every CFBundleDocumentTypes must contain?

- is it really the case that I don't need the AppDelegate? It currently
makes sense to me but maybe I'm missing something?

- I don't want to put the window in init, where else should I put it? Does
NSDocument have an equivalent of applicationDidFinishLaunching, i.e. when
the document is created is there any callback fired?

- new windows are positioned over the previous ones - I know this is
because of that NSMakeRect() - the application created using Xcode (with
NIBs) put every new window slightly to the right, slightly below the
previous window - what is responsible for it? The NIB?

Lots of questions, I know. Thank you in advance for any help with answering
these!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Minimal document-based app

2012-05-01 Thread ecir hana
If nothing else, it would explain to me how things works, 20 lines of
code would help me better than 20 documentation pages. There tutorials
above certainly did the explaining very well.

Also, I don't really want to argue whether there is merit or not - I
would be more thankful for the eventual tutorial or code sample.


On Tue, May 1, 2012 at 8:08 AM, Graham Cox graham@bigpond.com wrote:
 I see no merit in trying to make a minimal document based app, whatever 
 that is. It's usually misguided to try and build UI in code, it saves you 
 nothing and makes it much harder to get anywhere.

 Just start a new Cocoa app and use the project template for a document based 
 app. It gives you the necessary starting points, which though it adds a nib, 
 it's extremely small. There is nothing to be gained by going some other route.

 --Graham


 On 30/04/2012, at 7:47 AM, ecir hana wrote:

 Dear list,

 I'm trying to understand how the things in Cocoa works but I'm
 struggling with one thing. I saw
 http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html and
 http://casperbhansen.wordpress.com/2010/08/15/dev-tip-nibless-development/
 and I think I somewhat understood.

 Now, I would like to do the same but for a Document-based
 application. Please, does anyone know of a tutorial or example akin
 to the ones above? Alternatively, what do I need to do to make it
 work? I think I need to create NSDocumentController - but how does it
 relate to NSApplication? And I create NSDocument from there? Frankly,
 I'm bit lost...

 Thank you very much in advance!

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Minimal document-based app

2012-04-30 Thread ecir hana
Dear list,

I'm trying to understand how the things in Cocoa works but I'm
struggling with one thing. I saw
http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html and
http://casperbhansen.wordpress.com/2010/08/15/dev-tip-nibless-development/
and I think I somewhat understood.

Now, I would like to do the same but for a Document-based
application. Please, does anyone know of a tutorial or example akin
to the ones above? Alternatively, what do I need to do to make it
work? I think I need to create NSDocumentController - but how does it
relate to NSApplication? And I create NSDocument from there? Frankly,
I'm bit lost...

Thank you very much in advance!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com