Friday, December 15, 2017

#1 2007-11-15 07:17:43 pm

Budgie
Member
From:: New Zealand
Registered: 2005-02-22
Posts: 643

open panel in different area

Hi

Is it possible to have a panel open half way down a main window, instead of opening from the top of a main window?
if it is possible how would I go about making it happen please.?


Budgie

"Our greatest glory is not in never falling, but in rising every time we fall"    - Batman

Offline

 

#2 2007-11-18 02:44:11 am

Dominik
Member
Registered: 2006-02-09
Posts: 493

Re: open panel in different area

Hi Budgie,

it is possible. But you need to ceate a transparent window at the place where you want to show your panel. I would use a NSWindow subclass and give it some methods to create and remove a 'slave' (child) window:

[code]//  MasterAndSlaveWindow.h

#import <Cocoa/Cocoa.h>


@interface MasterAndSlaveWindow : NSWindow {
    NSWindow *slaveWin;
}

-(void)addSlaveWithXOffset:(float)xOffset yOffset:(float)yOffset;
-(NSWindow *)slave;
-(void)removeSlave;[/code]
[code]//  MasterAndSlaveWindow.m

#import "MasterAndSlaveWindow.h"

@implementation MasterAndSlaveWindow

- (id) init{
    self = [super init];
    if (self != nil) {
        slaveWin = nil;
    }
    return self;
}

- (void) dealloc{
    if (slaveWin != nil) [slaveWin release];
    [super dealloc];
}

-(void)addSlaveWithXOffset:(float)xOffset yOffset:(float)yOffset{

    if(slaveWin != nil) [slaveWin release];

    NSRect slaveFrame = [self frame];
    slaveFrame.origin.x += xOffset;
    slaveFrame.origin.y += yOffset;

    slaveWin = [[NSWindow alloc] initWithContentRect:slaveFrame
                styleMask:NSBorderlessWindowMask
                backing:NSBackingStoreBuffered
                defer: NO];
    [slaveWin setOpaque:NO];
    [slaveWin setBackgroundColor:[NSColor clearColor]];
    [self addChildWindow:slaveWin ordered:NSWindowAbove];
    [slaveWin makeKeyAndOrderFront:nil];
}

-(NSWindow *)slave{
    return slaveWin;
}

-(void)removeSlave{
    [self removeChildWindow:slaveWin];
    [slaveWin orderOut:nil];
    [slaveWin release];
}

@end[/code]
- add these two files to you project
- drop the .h file on your nib in Interface builder and set the new Window class as custom class in Interface Builder (Apple+5 in IB < 3.0 or Apple+6 in IB 3.0)
- then you can use it from AppleScript:

Applescript:

call method "addSlaveWithXOffset:yOffset:" of (window "window") with parameters {20.0, -140.0} -- create an invisible 'slave' window with the given offset
set can choose directories of open panel to true
set can choose files of open panel to false
display open panel attached to (call method "slave" of (window "window")) -- ask your window for it's slave and attach the panel to it

Hope that helps ...

D.

Offline

 

#3 2007-11-19 01:08:50 pm

Budgie
Member
From:: New Zealand
Registered: 2005-02-22
Posts: 643

Re: open panel in different area

Hi Dominik

Cheers for code and instruction, very much appreciated.


Budgie

"Our greatest glory is not in never falling, but in rising every time we fall"    - Batman

Offline

 

#4 2012-06-12 10:01:34 am

scsmith
Member
Registered: 2012-05-21
Posts: 11

Re: open panel in different area

First of all, I'm a newbie! I've used applescript for a decade, but am only just starting to use Xcode/ASOC. I have to thank the entire macscripter community for all their posts.  I've learned a lot and made great progress on a project I'm working on.  I want to particularly thank Shane for his book which I've just purchased, and have to thank Ric for his assistance implementing core data in my project.

Dominik wrote:

Hi Budgie,

it is possible. But you need to ceate a transparent window at the place where you want to show your panel. I would use a NSWindow subclass and give it some methods to create and remove a 'slave' (child) window:


This is exactly what I need(i think), but I can't seem to make it build in Xcode 4.3.2.  Getting error on the MasterAndSlaveWindow.m file with  "missing end" and another error......I've copied/pasted correctly, but assume that updates to Xcode require some changes to the code? I've searched but not finding anything helpful (likely because I don't know what I'm looking for)

Is there a "simple" update that can make this work in Lion/Xcode 4.3.2? smile

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)