home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / smalltk / src / stdwin.st < prev    next >
Text File  |  1991-10-12  |  11KB  |  447 lines

  1. Class StandardWindows Object
  2. Class Window Object number title menus size
  3. Class   TextWindow Window text
  4. Class   GraphicsWindow Window
  5. Class      DictionaryWindow GraphicsWindow dict select action
  6. Class         BrowserWindow DictionaryWindow class method mw tw
  7. Class EventManager Process responses
  8. Class Menu Object number title itemtitles items enablestatus
  9. Methods Window 'all'
  10.     new
  11.         title <- ''.
  12.         menus <- List new.
  13.         (1 to: 15) do: [:i | (windows at: i) isNil
  14.             ifTrue: [ windows at: i put: self.
  15.                     number <- i.  ^ self ] ]
  16. |
  17.     attachMenu: menu
  18.         menus addLast: menu.
  19.         <162 number 2 (menu number)>
  20. |
  21.     activate
  22.         ^ nil
  23. |
  24.     deactivate
  25.         ^ nil
  26. |
  27.     drawEvent
  28.         " overridden in subclasses "
  29.         ^ nil
  30. |
  31.     mouseMoveTo: mouseLocation
  32.         " mouse moved with button down "
  33.         ^ nil
  34. |
  35.     mouseDownAt: mouseLocation
  36.         " mouse down, do nothing "
  37.         ^ nil
  38. |
  39.     mouseUpAt: mouseLocation
  40.         " mouse up "
  41.         ^ nil
  42. |
  43.     command: n
  44.         (n = 1) ifTrue: [ self close ]
  45. |
  46.     reSized
  47.         size <- <161 number 6>
  48. |
  49.     open
  50.         " open our window, unless already opened "
  51.         <160 number title 0>.
  52.         menus do: [:m | <162 number 2 (m number)> ].
  53.         self reSized.
  54. |
  55.     charTyped: c
  56.         smalltalk beep
  57. |
  58.     title: text
  59.         title <- text.
  60.         <164 number title>
  61. |
  62.     close
  63.         " close up shop "
  64.         <161 number 1>.
  65.         windows at: number put: nil
  66. ]
  67. Methods TextWindow 'all'
  68.     open
  69.         "open the window with implicit text buffer"
  70.         <160 number title 1>.
  71.         " now do other initialization "
  72.         super open
  73. |
  74.     activate
  75.         super activate.
  76.         printer <- self.
  77. |
  78.     deactivate
  79.         super deactivate.
  80.         printer <- stdout.
  81. |
  82.     text
  83.         " read updated text and store it"
  84.         ^ text <- <165 number>
  85. |
  86.     print: text
  87.         <166 number text>
  88. |
  89.     draw
  90.         "redraw window"
  91.         <161 number 2>.
  92.         <161 number 5>.
  93.         <161 number 3>
  94. ]
  95. Methods GraphicsWindow 'all'
  96.     startDrawing
  97.         <161 number 2>
  98. |
  99.     endDrawing
  100.         <161 number 3>
  101. |
  102.     drawEvent
  103.         self startDrawing.
  104.         self draw.
  105.         self endDrawing.
  106. |
  107.     draw
  108.         " done by subclasses "
  109.         ^ nil
  110. |
  111.     at: x and: y print: text
  112.         <190 x y text>
  113. ]
  114. Methods DictionaryWindow 'all'
  115.     action: aBlock
  116.         action <- aBlock
  117. |
  118.     dictionary: d
  119.         dict <- d.
  120.         <163 number 2 40 (12* d size)>
  121. |
  122.     draw        | loc |
  123.         loc <- 0.
  124.         dict binaryDo: [:x :y |
  125.             self at: 0 and: loc print: x asString.
  126.             loc <- loc + 12 ].
  127.         <163 number 2 40 loc >.
  128.         select notNil
  129.             ifTrue: [ select invert ].
  130. |
  131.     mouseDownAt: mouseLocation    | y loc |
  132.         self invertSelection.
  133.         y <- mouseLocation y.
  134.         loc <- 0.
  135.         dict binaryDo: [:a :b |
  136.             loc <- loc + 12.
  137.             (loc > y) ifTrue: [ 
  138.                 select <- 0@(loc - 10) to: size x@loc.
  139.                 self invertSelection. 
  140.                 action value: b. ^ nil ]]
  141. |
  142.     invertSelection
  143.         self startDrawing.
  144.         (select notNil)
  145.             ifTrue: [ select invert ].
  146.         self endDrawing.
  147. ]
  148. Methods BrowserWindow 'all'
  149.     new
  150.         super new.
  151.         dict <- classes.
  152.         action <- [:c | self selectClass: c ].
  153.         self makeBrowserMenu.
  154. |
  155.     close
  156.         " close all our windows "
  157.         tw notNil ifTrue: [ tw close ].
  158.         mw notNil ifTrue: [ mw close ].
  159.         super close.
  160. |
  161.     selectClass: c
  162.         class <- c.
  163.         browserMenu enableItem: 2.
  164.         browserMenu disableItem: 3.
  165.         browserMenu disableItem: 4.
  166.         tw notNil ifTrue: [ tw close ].
  167.         mw notNil ifTrue: [ mw close ].
  168.         self openMethodWindow
  169. |
  170.     openMethodWindow
  171.         tw notNil ifTrue: [ tw close ].
  172.         browserMenu disableItem: 3.
  173.         mw notNil ifTrue: [ mw close ].
  174.         browserMenu enableItem: 2.
  175.         mw <- DictionaryWindow new; 
  176.             title: class printString,  ' Methods';
  177.             dictionary: class methods;
  178.             action: [:c | self selectMethod: c ];
  179.             attachMenu: browserMenu;
  180.             open.
  181. |
  182.     selectMethod: m
  183.         method <- m.
  184.         tw notNil ifTrue: [ tw close ].
  185.         tw <- TextWindow new; 
  186.             title: class printString , ' ', m asString;
  187.             attachMenu: browserMenu;
  188.             open.
  189.         browserMenu enableItem: 3.
  190.         tw print: m text
  191. |
  192.     makeBrowserMenu
  193.         browserMenu isNil ifTrue: 
  194.             [ browserMenu <- Menu new; title: 'Browser'; create.
  195.             browserMenu addItem: 'add class'
  196.                 action: [:w | self addClass ].
  197.             browserMenu addItem: 'add method'
  198.                 action: [:w | self addMethod ].
  199.             browserMenu addItem: 'compile'
  200.                 action: [:w | self compile ].
  201.             browserMenu addItem: 'command'
  202.                 action: [:w | self doCommand ] ].
  203.         browserMenu disableItem: 2.
  204.         browserMenu disableItem: 3.
  205.         browserMenu disableItem: 4.
  206.         self attachMenu: browserMenu
  207. |
  208.     addClass    
  209.         " add a new class "
  210.         tw notNil ifTrue: [ tw close ].
  211.         browserMenu enableItem: 4.
  212.         tw <- TextWindow new; title: 'New Class Information';
  213.             open; attachMenu: browserMenu;
  214.             print: 'superClass addSubClass: #nameOfClass ',
  215.                 'instanceVariableNames: ''var1 var2'' '
  216. |
  217.     addMethod
  218.         method <- Method new.
  219.         tw notNil ifTrue: [ tw close ].
  220.         tw <- TextWindow new; 
  221.             title: class printString , ' new method'.
  222.         tw open; attachMenu: browserMenu.
  223.         browserMenu enableItem: 3.
  224. |
  225.     compile
  226.         method text: tw text.
  227.         (method compileWithClass: class)
  228.             ifTrue: [ class methods at: method name put: method.
  229.                 mw drawEvent ].
  230. |
  231.     doCommand
  232.         " accept tw command "
  233.         [ tw text execute. tw close. self drawEvent ] fork.
  234. ]
  235. Methods Menu 'all'
  236.     new
  237.         items <- Array new: 0.
  238.         itemtitles <- Array new: 0.
  239.         enablestatus <- Array new: 0.
  240.         (1 to: 15) do: [:i | (menus at: i) isNil
  241.             ifTrue: [ menus at: i put: self.
  242.                     number <- i.  ^ self ] ]
  243. |
  244.     number
  245.         ^ number
  246. |
  247.     addItem: name action: aBlock
  248.         items <- items with: aBlock.
  249.         itemtitles <- itemtitles with: name.
  250.         enablestatus <- enablestatus with: true.
  251.         <181 number name nil>
  252. |
  253.     enableItem: n
  254.         enablestatus at: n put: true.
  255.         <182 number n 1 1>
  256. |
  257.     disableItem: n
  258.         enablestatus at: n put: false.
  259.         <182 number n 1 0>
  260. |
  261.     selectItem: n inWindow: w
  262.         " execute the selected menu item "
  263.         (items at: n) value: w
  264. |
  265.     title: aString
  266.         " give the title to a menu item"
  267.         title <- aString
  268. |
  269.     create
  270.         "create menu"
  271.         <180 number title>.
  272.         " reinstate any old items "
  273.         (1 to: items size) do:
  274.             [:i | <181 number (itemtitles at: i) nil>. 
  275.                 (enablestatus at: i) 
  276.                     ifFalse: [ self disableItem: i]]
  277. ]
  278. Methods EventManager 'all'
  279.     new
  280.         responses <- Array new: 12.
  281.         responses at: 1 put: [:w | w activate ].
  282.         responses at: 2 put: [:w | w charTyped: (Char new; value: <171 4>) ].
  283.         responses at: 3 put: [:w | w command: <171 9> ].
  284.         responses at: 4 put: [:w | w mouseDownAt: self mouseLocation ].
  285.         responses at: 5 put: [:w | w mouseMoveTo: self mouseLocation ].
  286.         responses at: 6 put: [:w | w mouseUpAt: self mouseLocation ].
  287.         responses at: 7 put: [:w | self eventMenu 
  288.             selectItem: self menuItem inWindow: w ].
  289.         responses at: 8 put: [:w | w reSized ].
  290.         responses at: 9 put: [:w | w moved ].
  291.         responses at: 10 put: [:w | w drawEvent ].
  292.         responses at: 11 put: [:w | w timer ].
  293.         responses at: 12 put: [:w | w deactivate ].
  294. |
  295.     eventWindow
  296.         ^ windows at: <171 1>
  297. |
  298.     eventMenu
  299.         ^ menus at: <171 2>
  300. |
  301.     menuItem
  302.         ^ <171 3>
  303. |
  304.     mouseLocation
  305.         " return the current location of the mouse "
  306.         ^ <172 1>
  307. |
  308.     execute        | i |
  309.         " process one event "
  310.         i <- <170>.  (i = 0)
  311.         ifFalse: [ (responses at: i) value: self eventWindow ]
  312. ]
  313. Methods StandardWindows 'all'
  314.     makeSystemMenu
  315.         systemMenu isNil ifTrue:
  316.             [ systemMenu <- Menu new; title: 'System'; create.
  317.             systemMenu addItem: 'browser' 
  318.                 action: [:w | BrowserWindow new; title: 'Browser'; open ].
  319.             systemMenu addItem: 'file in'
  320.                 action: [:w | [ File new; 
  321.                     fileIn: (smalltalk askFile: 'file name:')] fork ].
  322.             systemMenu addItem: 'save image'
  323.                 action: [:w | [ smalltalk saveImage: 
  324.                     (smalltalk askNewFile: 'image file:') ] fork ].
  325.             systemMenu addItem: 'quit'
  326.                 action: [:w | scheduler quit ]
  327.             ]
  328. |
  329.     makeWorkspaceMenu
  330.         workspaceMenu isNil ifTrue: [
  331.             workspaceMenu <- Menu new; title: 'Workspace'; create.
  332.             workspaceMenu addItem: 'print it'
  333.                 action: [:w | [ w print:  w text value asString ] fork ].
  334.             workspaceMenu addItem: 'do it'
  335.                 action: [:w | [ w text execute ] fork ]]
  336. |
  337.     makeWorkspace
  338.         TextWindow new; title: 'Workspace';
  339.             open; attachMenu: systemMenu; attachMenu: workspaceMenu.
  340. ]
  341. *
  342. * initialization code
  343. * this is executed once, by the initial image maker
  344. *
  345. *
  346. Methods Smalltalk 'doit'
  347.     error: aString    | ew |
  348.         " print a message, and remove current process "
  349.         scheduler currentProcess trace.
  350.         <204 aString>.
  351.         scheduler currentProcess terminate
  352. ]
  353. Methods Scheduler 'get commands'
  354.     initialize
  355.         stdwin makeSystemMenu.
  356.         stdwin makeWorkspaceMenu.
  357.         stdwin makeWorkspace.
  358.         eventManager <- EventManager new.
  359.         scheduler addProcess: eventManager
  360. |
  361.     quit
  362.         " all done - really quit "
  363.         " should probably verify first "
  364.         notdone <- false
  365. ]
  366. Methods UndefinedObject 'initial image'
  367.     createGlobals
  368.         " create global variables in initial image "
  369.         true <- True new.
  370.         false <- False new.
  371.         smalltalk <- Smalltalk new.
  372.         files <- Array new: 15.
  373.         stdin <- File new; name: 'stdin'; mode: 'r'; open.
  374.         stdout <- File new; name: 'stdout'; mode: 'w'; open.
  375.         stderr <- File new; name: 'stderr'; mode: 'w'; open.
  376.         printer <- stdout.
  377.         " create a dictionary of classes "
  378.         classes <- Dictionary new.
  379.         symbols binaryDo: [:x :y | 
  380.             (y class == Class)
  381.                 ifTrue: [ classes at: x put: y ] ].
  382.         scheduler <- Scheduler new.
  383.         stdwin <- StandardWindows new.
  384.         windows <- Array new: 15.
  385.         menus <- Array new: 15.
  386.         windows <- Array new: 15.
  387. |
  388.     initialize    | aBlock |
  389.         " initialize the initial object image "
  390.         self createGlobals.
  391.         " create the initial system process "
  392.         " note the delayed recursive call "
  393.         aBlock <- [ files do: [:f | f notNil ifTrue: [ f open ]].
  394.                 menus do: [:m | m notNil ifTrue: [ m create ]].
  395.                 windows do: [:w | w notNil ifTrue: [ w open ]].
  396.                 systemProcess <- aBlock newProcess.
  397.                 scheduler run ].
  398.         systemProcess <- aBlock newProcess.
  399.         File new;
  400.             name: 'systemImage';
  401.             open: 'wb';
  402.             saveImage;
  403.             close.
  404. ]
  405. Methods String 'test'
  406.     print
  407.         ^ printer print: self
  408. ]
  409. Methods Smalltalk 'interface'
  410.     getPrompt: aString
  411.         ^ <201 aString ''>
  412. |
  413.     askNewFile: prompt
  414.         " ask for a new file name "
  415.         ^ <203 prompt '' 1>
  416. |
  417.     askFile: prompt
  418.         ^ <203 prompt '' 0>
  419. |
  420.     inquire: aString
  421.         ^ <202 aString 1>
  422. ]
  423. Methods Rectangle 'drawing'
  424.     frame
  425.         <194 1 left top right bottom>
  426. |
  427.     paint
  428.         <194 2 left top right bottom>
  429. |
  430.     erase
  431.         <194 3 left top right bottom>
  432. |
  433.     invert
  434.         <194 4 left top right bottom>
  435. |
  436.     shade: aPercent
  437.         <195 1 left top right bottom aPercent>
  438. ]
  439. Methods Smalltalk 'beep'
  440.     beep
  441.         <205>
  442. ]
  443. Methods Circle 'drawing'
  444.     frame
  445.         <193 1 (center x) (center y) radius>
  446. ]
  447.