2013-12-14 44 views
2

我已經做了一個子類#Mosaic1的#SystemWindow,我想控制窗口的初始位置。我怎麼做?類#RealEstateAgent涉及但如何?班級評論說SystemWindow的初始位置(Cuis Smalltalk)

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 

所以我要求解釋如何配置和使用類#RealEstateAgent。

注:

  • #RealEstateAgent是一個單。它只有類端方法
  • 它僅由#SystemWindow
  • 新SystemWindow從RealEstateAgent類獲取其初始程度引用>> standardWindowExtent

回答

1

一種解決方案是繞過類# RealEstateAgent並編寫自己的代碼來處理SystemWindow的新實例的初始大小和位置。

這可以通過重寫SystemWindow >> openInWorld完成:程度:

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 ] 

替換

self morphPosition: 
     (RealEstateAgent initialFrameFor: self world: aWorld) topLeft; 
     morphExtent: extent. 

計算

  • thePositionOfTheWindow
  • theExtentOfTheWindow

然後做

self morphPosition: thePositionOfTheWindow morphExtent: theExtentOfTheWindow.