I have made a subclass #Mosaic1 of #SystemWindow and I would like to control the initial position of the window. How do I do that? Class #RealEstateAgent is involved but how? The class comment says
Responsible for real-estate management on the screen,
which is to say, controlling where new windows appear,
with what sizes, etc. 5/20/96 sw
So I am asking for an explanation how to configure and use the class #RealEstateAgent.
Notes:
#RealEstateAgent is a singleton. It only has class side methods
It is only referenced by #SystemWindow
A new SystemWindow gets its initial extent from RealEstateAgent class>> standardWindowExtent
One solution is to bypass the class #RealEstateAgent and write your own code to handle the initial size and position of a new instance of SystemWindow.
This may be done by overriding SystemWindow>>openInWorld:extent:
openInWorld: aWorld extent: extent
"This msg and its callees result in the window being activeOnlyOnTop"
aWorld addMorph: self.
self morphPosition:
(RealEstateAgent initialFrameFor: self world: aWorld) topLeft;
morphExtent: extent.
aWorld startSteppingSubmorphsOf: self.
"Do it deferred. Was needed for text cursor to start blinking
if (Preferences disable: #focusFollowsMouse) "
WorldState addDeferredUIMessage: [ self activate ]
Replace
self morphPosition:
(RealEstateAgent initialFrameFor: self world: aWorld) topLeft;
morphExtent: extent.
Calculate
thePositionOfTheWindow
theExtentOfTheWindow
Then do
self morphPosition: thePositionOfTheWindow morphExtent: theExtentOfTheWindow.
Related
I'm trying to switch out a direct integer with a variable in swift, but for some reason I'm getting this error and I have no idea. The end goal is to get my currentValue (line 76) to replace the 100's on line 41 - could anyone let me know how I could accomplish this without the error? New to swift and having a hard time (background in objective-c, figured something this simple would not stop me in my tracks!)
Full .swift file here: http://pastebin.com/K6UHkNEv
EDIT:
// these values change the number of squares
let _gameView = CGOLView(gridWidth:100, gridHeight:100)
#IBOutlet weak var tileSizeSlider: UISlider!
#IBAction func sliderValueChanged(sender: UISlider) {
var currentValue = Int(sender.value)
print("\(currentValue)")
}
should work as:
// these values change the number of squares
let _gameView = CGOLView(gridWidth:currentValue, gridHeight:currentValue)
#IBOutlet weak var tileSizeSlider: UISlider!
#IBAction func sliderValueChanged(sender: UISlider) {
var currentValue = Int(sender.value)
print("\(currentValue)")
}
instead I get this error:
Use of unresolved identifier 'currentValue'
and if I try to create custom int's and input them:
var gridWidthValue = 50
var gridHeightValue = 50
like this:
let _gameView = CGOLView(gridWidth:gridWidthValue, gridHeight:gridHeightValue)
I get:
'ViewController.Type' does not have a member named 'gridHeightValue'
Any help would be appreciated - thanks stackoverflow community!
David.
currentValue is a local variable to sliderValueChanged.
Instead you should instantiate _gameView in init. Note however, you still won't be able to use currentValue.
If this is a one off sort of thing, you can always make _gameView an optional and then create it when you have adjusted the slider. This is admittedly a little clumsy.
I am not familiar with Conway's Game of Life, but looking at the code, it seems CGOLView's init does some adjustment based on the grid width and height. The reason I am mentioning this is that you could always change the view's frame size, however, you'd then also need to make some other mods to the tileViews for it to look proper.
As to why gridWidthValue/gridHeightValue is not working. Those are properties defined in an instance. Hence you would need to do somethign like self.gridWithValue to reference it. However, you cannot do that when defining the property such as
let _gameView = CGOLView(gridWidth:gridWidthValue, gridHeight:gridHeightValue)
This is also why instantiating _gameView in init is the way to go.
Your problem is that you cannot access the variable currentValue because it is inside of a function. You have to declare that value outside of the function to be able to use it outside of the function.
I would like to be able to drag and drop and email from Outlook for Mac and from Mail.app into an OS X app. If I drag and drop and email from my finder (drag a file), then the following is called:
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
However, if I drag and drop from Outlook for Mac or from Mail.app, the method isn't called. I'm a bit lost on how can I achieve this. Any ideas?
From the Dragging Destinations portion of Drag and Drop Programming Topics:
To receive drag operations, you must register the pasteboard types that your window or view will accept by sending the object a registerForDraggedTypes: message, defined in both NSWindow and NSView, and implement several methods from the NSDraggingDestination protocol. During a dragging session, a candidate destination receives NSDraggingDestination messages only if the destination is registered for a pasteboard type that matches the type of the pasteboard data being dragged. The destination receives these messages as an image enters, moves around inside, and then exits or is released within the destination’s boundaries.
In order to accept drags from Mail you'll need to know what pasteboard types to register for. You can use ClipboardViewer to discover what types of data Mail places on the dragging pasteboard (available in the Auxiliary Tools package for recent versions of Xcode). Launch ClipboardViewer and select Drag Clipboard from the combo box in the toolbar. Switch back to Mail and drag a message briefly, then return to ClipboardViewer. You should see a number of pasteboard types listed in the sidebar. Of particular interest will be the public.url and com.apple.pasteboard.promised-file-content-type types. The former indicates that a URL is on the pasteboard. The latter that a file promise is on the pasteboard. URLs tend to be a good place to start, but in this particular case we can see that the URL isn't something useful like a file URL, it's a rather opaque message URL. That means we need to deal with the file promise instead, and so when configuring our view to receive drags we should call registerForDraggedTypes: with NSFilesPromisePboardType.
The second part of the Dragging File Promises documentation outlines specifically how to deal with receiving promises. To summarize, you call -namesOfPromisedFilesDroppedAtDestination: on the sender of the drag from within performDragOperation: to have them write the dragged data to a location of your choosing (e.g., fulfill the promise). The originator of the drag will write the data to disk before AppKit invokes concludeDragOperation: on your object. At any point from concludeDragOperation: forwards you can load the dropped files from disk and process them as you wish.
I thought I would post my answer to this problem as I struggled with it for a while. This code handles a promise and simply copies the dropped mail into a folder called Drop Stuff in your user folder. It also works for any file too and seems to work for other apps including address book and reminders etc. It doesn't work for copying multiple files (or mail messages) yet.
import Cocoa
class DropArea: NSImageView, NSDraggingDestination
{
override func drawRect(dirtyRect: NSRect)
{
super.drawRect(dirtyRect)
}
required init?(coder: NSCoder)
{
let types = [NSFilenamesPboardType, NSURLPboardType, NSPasteboardTypeTIFF, NSFilesPromisePboardType]
super.init(coder: coder)
registerForDraggedTypes(types)
}
override func draggingEntered(sender: NSDraggingInfo) -> NSDragOperation
{
return .Copy
}
override func performDragOperation(sender: NSDraggingInfo) -> Bool
{
var error: NSError?
var folderPath = NSHomeDirectory()+"/Drop Stuff/"
if (!NSFileManager.defaultManager().fileExistsAtPath(folderPath))
{
NSFileManager.defaultManager().createDirectoryAtPath(folderPath, withIntermediateDirectories: true, attributes: nil, error: &error)
}
var folderURL = NSURL(fileURLWithPath: folderPath)
var f = sender.namesOfPromisedFilesDroppedAtDestination(folderURL!)
println("Copied to \(folderPath)")
return true
}
}
Any suggestions to improve this code are of course welcome :-)
I'm having a problem in using XNA Math in a DLL I'm creating. I have a class that is in a DLL and is going to be exported. It has a member variable of type XMVECTOR. In the class constructor, I try to initialize the XMVECTOR. I get a Access Violation in reading from reading location 0x0000000000
The code runs something like this:
class DLLClass
{
public:
DLLClass(void);
~DLLClass(void);
protected:
XMVECTOR vect;
XMMATRIX matr;
}
DLLClass::DLLClass(void)
{
vect = XMLoadFloat3(&XMFLOAT3(0.0f, 0.0f, 0.0f)); //this is the line causing the access violation
}
Note that this class is in a DLL that is going to be exported. I do not know if this will make a difference by just some further info.
Also while I'm at it, I have another question:
I also get the warning: struct '_XMMATRIX' needs to have dll-interface to be used by clients of class 'DLLClass'
Is this fatal? If not, what does it mean and how can I get rid of it? Note this DLLClass is going to be exported and the "clients" of the DLLClass is probably going to use the variable 'matr'.
Any help would be appreciated.
EDIT: just some further info: I've debugged the code line by line and it seems that the error occurs when the return value of XMLoadFloat3 is assigned to the vect.
This code is only legal if you are building with x64 native -or- if you use __aligned_malloc to ensure the memory for all instances of DLLClass are 16-byte aligned. x86 (32-bit) malloc and new only provide 8-byte alignment by default. You can 'get lucky' but it's not stable.
class DLLClass
{
public:
DLLClass(void);
~DLLClass(void);
protected:
XMVECTOR vect;
XMMATRIX matr;
}
See DirectXMath Programming Guide, Getting Started
You have three choices:
Ensure DLLClass is always 16-byte aligned
Use XMFLOAT4 and XMFLOAT4X4 instead and do explicit load/stores
Use the SimpleMath wrapper types in DirectX Tool Kit instead which handle the loads/stores for you.
You shouldn't take the address of an anonymous variable:
vect = XMLoadFloat3(&XMFLOAT3(0.0f, 0.0f, 0.0f));
You need
XMFLOAT3 foo(0.0f, 0.0f, 0.0f);
vect = XMLoadFloat3(&foo);
How do I translate the following method call from ObjectiveC to RubyMotion syntax:
[self.faceView addGestureRecognizer:[
[UIPinchGestureRecognizer alloc] initWithTarget:self.faceView
action:#selector(pinch:)]];
I got this far:
self.faceView.addGestureRecognizer(
UIPinchGestureRecognizer.alloc.initWithTarget(
self.faceView, action:???))
I understand the #selector(pinch:) indicates a delegation to the receiver object pinch method, but how would I do this in RubyMotion? Maybe using a block?
You should be able to just use a string to specify the selector:
self.faceView.addGestureRecognizer(
UIPinchGestureRecognizer.alloc.initWithTarget(
self.faceView, action:'pinch'))
#gesture = UIPinchGestureRecognizer.alloc.initWithTarget(self.faceView,action:'pinch:')
self.faceView.addGestureRecognizer(#gesture)
def pinch(foo)
end
If you don't want the method handler to take an argument, use action:'pinch' instead. It will then look for a method like this:
def pinch
end
Using an instance var (#gesture = ...) is a good idea here because sometimes gesture recognizers and the GC don't play well together if you don't make the gesture var an instance var of a UIViewController. (In my experience)
I've got a contributed command and a handler for it. The handler's execute event has to get the value for the property actually selected in the properties view and act on it, or to be disabled if no property selected.
I've tried:
1) Set the selection provider to something which provides selection from the property view. Something in this case is just PropertySheetViewer for my PropertySheetPage, but i can't set it as the selection provider because the PropertySheetPage's viewer is private and has no getter.
2) Overriding PropertySheetPage's createControl method: This method creates a Tree control for the PropertySheetViewer. A selection listener can be installed for that tree control, so maybe i can make my command handler implement SelectionListener... The solution would be somethin like:
In my editor:
public Object getAdapter(#SuppressWarnings("rawtypes") Class type) {
if (type == IPropertySheetPage.class) {
PropertySheetPage page = new PropertySheetPage() {
#Override
public void createControl(Composite parent) {
super.createControl(parent);
IHandler handler = someWayToGetMyCmdHandler();
((org.eclipse.swt.widgets.Tree) getControl())
.addSelectionListener(handler);
}
};
IPropertySheetEntry entry = new UndoablePropertySheetEntry(
getCommandStack());
page.setRootEntry(entry);
return page;
}
return super.getAdapter(type);
}
And my command handler implementing SelectionListener as i said... The problem with this approach is that i can't find a way to get a reference to my contributed command handler (someWayToGetMyCmdHandler() above).
Has anybody got any clue on this, or any other possible approach to the problem??
There's handleEntrySelection(ISelection selection) method in PropertySheetPage that you could override to be notified about selection changes in the viewer (although PropertySheetPage is #noextend).
The second part (updating the handler) is a bit more tricky than it would normally be. Commands/handlers get updated automatically when workbench selection changes (you just need to implement setEnabled(Object evaluationContext) AbstractHandler). But since PropertySheetPage is designed to change its input on global selection change, then you have to find some custom way to notify/update your handler.
As I understand, it is currently not possible to extend the platform command event handling mechanism with custom variables, so you just need to directly look up your handler using IHandlerService of the workbench.