SystemWindow的初始位置(Cuis Smalltalk)

时间:2013-12-14 00:25:19

标签: smalltalk morphic

我已经创建了 #SystemWindow 的子类#Casite1,我想控制窗口的初始位置。我怎么做?涉及班级 #RealEstateAgent ,但如何?课堂评论说

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 个答案:

答案 0 :(得分: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.