2 Windows adjacent to each other.

Discussion in 'Mac Programming' started by Marimuthu, Jul 20, 2011.

  1. Marimuthu macrumors member

    Oct 18, 2010

    My environment is Snow Leopard with Xcode 3.2 with Cocoa framework.

    My application requirement is that there must be 2 NSWindow which are placed adjacent to each other and attached to each other. One of the windows is movable and when that moves, the 2nd window also moves. the Second window doesnot have a title bar.

    In the view class of the 1st Window, I am able to track/handle mouse movement on the 1st window (like mouse enter, mouse exit) and other window movement related notifications like windowDidMove, WindowwillMove etc and move the position of the 2nd window such that it is attached to the 1st window. But the movement of the second window is not smooth at all (i mean after I left click on title bar, drag the mouse and release the 1st window will the related window move notification be fired where I draw the 2nd window)and the user experience is quiet awful.

    Is there a mechanism where I tell the framework that the 2nd window's position is fixed with respect to the 1st window.
    Alternatively is there a mechanism where I can track the movement of 1st window continuously such that I can smoothly draw the 2nd window.

    Thanks in advance.
  2. gnasher729 macrumors P6


    Nov 25, 2005
    You should get windowDidMove notifications continuously while the first window is being dragged, and if you move the second window right when you get the notification, things should be smooth. Is that what you are doing?
  3. robbieduncan Moderator emeritus


    Jul 24, 2002
    What documentation have you read to try and solve this problem? I ask as using the documentation is a key skill you should seek to develop. The answer is reasonably obvious if you look at the NSWindow reference documentation, specifically the addChildWindow:eek:rdered: method.
  4. Marimuthu thread starter macrumors member

    Oct 18, 2010
    I am trapping the windowdidMove notification to re-position the 2nd window. But I find that when left click the title bar of the 1st window and mouse the mouse (to move the 1st window), the 2nd window is not moved instantaneously. After moving the 1st window, it takes few milliseconds for the 2nd window to move from it's initial position to the new position.

    And the code to reposition the 2nd window is
    [window2 setFrame:newPostiion display:YES];
    [window2 update];
    The above code I call from the windowdidMove method.
    The movement as i told is not smooth at all.
  5. Marimuthu thread starter macrumors member

    Oct 18, 2010
    Apologies, I had not seen robbieduncan's response while posting my reply #4 above.

    I am in the learning phase hence have posted this thread whose solution might have been obvious to many.

    I, to be honest have not gone in detail through the reference document, rather have been goggling for the solution. As rightly pointed out, I need to depend more on the apple reference docs rather than looking for shortcuts.

    Thanks robbieduncan for the solution.
  6. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    That's the description of a window with an NSDrawer as the "secondary window".

    You already asked this question in another thread:

    I pointed you to the NSDrawer documentation.

    Are you saying you tried an NSDrawer and it didn't work, or did you not try NSDrawer? If it didn't work, describe why in more detail.

    If you haven't tried NSDrawer at all, then you should try it, because it's designed for exactly the situation you describe: a secondary window attached to a primary window.
  7. Marimuthu thread starter macrumors member

    Oct 18, 2010
    I did try with the NSDrawer control but I did not get the look and feel that was expected.

    For example, the drawer window comes with a border which wanted to avoid. I thought it might be tough to remove the drawer border.

    Secondly, the drawer window should have 2 sizes namely normal and expanded. When i hover over the normal state, it should expand to a bigger drawer. i was able to handle the tracking of the mouse over the drawer window and resize to a bigger window but when I do a mouse over (when the window is normal size), the cursor used to change from arrow to an expandable cursor which was not desired in my app.

    Moreover, I have to hover over the normal drawer window or click on the drawer window to resize to a bigger drawer window.

    I did start with the implementation with the NSDrawer control but was faced with the issues 1 and 2 stated above. Hence decided against it.

    Is there a way I can get around it, because otherwise, as you stated it does the necessary job.
  8. Marimuthu thread starter macrumors member

    Oct 18, 2010
    Dear All,

    I have been partially able to implement what I intend to achieve.
    Able to add a new NSWindow (window 2) adjacent to an existing window (window 1).
    On Mouse entry into the window 2's view, I am able to animate Window 2 and make it bigger and on mouse exit (using timers), I bring it to the normal size. This works when I don't move the main window (window 1) when the animation is in progress.

    However when the Window 2 is animated to it's normal size, if I were to vigorously move the 1st Window (left mouse click on title bar and move the mouse), the second Window get's displaced to some random position. Dont know as to why that is happening. I need the animation on resizing of the Window 2 as it an feature requirment.

    Am I missing something here? Am I doing the placing of the Windows and resizing of the window with animation in the right way?

    I have attached the project to this thread. Could you guys please go through the same and guide me forward.

    Please help.


    Attached Files:

  9. Marimuthu thread starter macrumors member

    Oct 18, 2010
    Hi All,
    Let me summarize the problem that I am facing.

    I want is have a 2 windows in my app, Window 1 is my main window, 2nd window (NSWindow) is placed adjacent to the parent window (window 1). This I was able to achieve.

    When the 2nd Window animates and resizes, if I were to move the 1st Window, the 2nd Window gets placed some where else. i guess the calling of the setFrame (to animate and resize the 2nd window) and the moving of window 1 is not in sync resulting in the behavior.

    Is there a way to address this issue? I have attached the project in the earlier post of mine.

    Waiting for experts to address this issue of mine.

  10. Marimuthu thread starter macrumors member

    Oct 18, 2010
    Can you guys guide me with some info as to how to customize the NSDrawer to achieve the above-mentioned behaviour. I tried searching for the same in google but could not find any useful info regarding customization of drawer to get the expected look and feel.
    A sample application project demonstrating an window sliding out and into the main window will also be of great help and it can act as a base from where i can carry forward.

Share This Page