Provide a progress bar with a custom text and Cancel button

Discussion in 'Mac Programming' started by rahulkesharwani, Nov 1, 2011.

  1. rahulkesharwani macrumors newbie

    Joined:
    Oct 30, 2011
    #1
    Hi

    I have a C++ framework and I would like to pop up a progress bar with a Cancel button and update the text on the progress bar at required times. I know I should use a NSProgressIndicator but could not make it work as I am very new to Cocoa. My progress bar should look like a indeterminate progress indicator and should be placed at the centre of the window of the application that uses my framework.

    Please note that mine is a C++ framework, not a Cocoa app. The links that I come across on web talks about creating NSProgressIndicator using Interface Builder etc. which I cant use. I have to do this programatically.

    Thanks & Regards
    Rahul
     
  2. MorphingDragon macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #2
    Is this a cross-platform framework or Mac OSX only?
     
  3. rahulkesharwani thread starter macrumors newbie

    Joined:
    Oct 30, 2011
  4. MorphingDragon macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #4
    Well you could utilize Objective-C++ and link to the Cocoa libraries. You can build up NSWindows programatically like you can with other GUI toolkits, it just takes a bit more effort.
     
  5. rahulkesharwani thread starter macrumors newbie

    Joined:
    Oct 30, 2011
    #5
    I am trying to do this programatically. Following is some of the code I have written:

    Code:
    NSWindow *myWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO];
    [myWindow center];
    bool isWindowVisible;
    isWindowVisible = [myWindow isVisible];
    [myWindow setViewsNeedDisplay:YES];
    NSProgressIndicator *myProgressIndicator;
    myProgressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
    [[myWindow contentView] addSubview:myProgressIndicator];
    [myProgressIndicator setHidden:NO];
    [myProgressIndicator startAnimation:myProgressIndicator];
    [myProgressIndicator stopAnimation:myProgressIndicator];
    
    
    But this doesn't display anything. I also see that isVisible returns false for my created window. What else should I do to make this work?
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Have you told your window to display itself? setViewsNeedDisplay: does not tell the window to make itself visible on screen. orderFront: does that.
     
  7. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #7
    Also, do you have a NSRunLoop running to handle the event dispatching? If you've called NSApplicationMain, then that will have setup up an NSRunLoop for you.
     
  8. rahulkesharwani thread starter macrumors newbie

    Joined:
    Oct 30, 2011
    #8
    I have tried using orderFront and makeKeyAndOrderFront methods for the NSWindow I created. With the latter, I sometimes get a white window but not always. I am not sure what is going wrong.

    Is it that I need to get the parent window of the application from within my framework and then draw my progress bar on that? If yes, how to do that.

    I would be very grateful if some one can provide a code sample to do what I am trying to do. Being a beginner in Cocoa, its taking me long to figure out things and I am a bit crunched on time.
     

Share This Page