home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / self / contrib.lha / contrib / 491 / aa / window.self < prev   
Encoding:
Text File  |  1993-07-22  |  12.4 KB  |  468 lines

  1. " object to control updating of AA window "
  2. "
  3. *
  4. * window.self,v 1.18 1993/07/22 00:15:23 richards Exp
  5. *
  6. * window.self,v
  7. * Revision 1.18  1993/07/22  00:15:23  richards
  8. * Moved back to having event handlers per operation.
  9. * eventHandler/buttons now support substitution.
  10. * poly.self has primitive substitution handler, except that it has
  11. * no concept of context.
  12. *
  13. * Revision 1.17  1993/07/18  20:22:37  richards
  14. * Added substitution of polynomials (not quite working properly yet).
  15. * Some tests for this added to test4.
  16. * Buttons work, selections work, and eventHandling is coming along.
  17. *
  18. * Revision 1.16  1993/07/14  21:42:10  richards
  19. * Moved event handling out of the equationView and into a seperate set of object.
  20. * Equation selecting works!
  21. *
  22. * Revision 1.15  1993/07/13  21:47:06  richards
  23. * July 13 checkin.
  24. *
  25. * Revision 1.14  1993/06/24  21:24:35  richards
  26. * Split drawing out of boites and into light weight views.
  27. *
  28. * Revision 1.13  1993/06/23  21:18:13  richards
  29. * Daily checkin.
  30. *
  31. * Revision 1.12  1993/06/23  02:04:26  richards
  32. * Progress towards being able to select equations.
  33. *
  34. * Revision 1.11  1993/06/23  00:36:10  richards
  35. * Fixed up test1 to work with new code.
  36. * boites and window have first hack at highlighting code.
  37. *
  38. * Revision 1.10  1993/06/21  21:39:26  richards
  39. * Added highlighting.
  40. * Moved gc cache into viewManager.
  41. *
  42. * Revision 1.9  1993/06/18  21:25:44  richards
  43. * Moved font support into viewManager.
  44. * Starting to add selection stuff into window and boite.
  45. * Boites refer properly back to the polynomial structures.
  46. *
  47. * Revision 1.8  1993/06/03  21:33:18  richards
  48. * Fixed up the redrawing of the subviews. Turned out they were being drawn off the screen
  49. * due to faulty thinking about where the areas really were.
  50. *
  51. * Revision 1.7  1993/06/02  21:17:10  richards
  52. * I am slowly dealing with window redrawing and resizing requests and getting deeper
  53. * into navel and X. The problem is either too many configureNotify requests, or not enough
  54. * of them. Also, there seems to be some kind of problem filing window.self in twice.
  55. *
  56. * Revision 1.6  1993/05/31  20:27:59  richards
  57. * symbols has the whole greek alphabet, but some letters are not named right.
  58. * window.self noww uses two sub-classes of compoundView, one inside the other.
  59. * (Still have problem identifying them...)
  60. * test7 obsolete.
  61. * Fixed some problems with font positioning in boites and poly.
  62. *
  63. * Revision 1.5  1993/05/31  15:00:12  richards
  64. * Changed the view to be two views: topView and an equationView. topView is divided up nicely.
  65. *
  66. * Revision 1.4  1993/05/31  00:12:20  richards
  67. * May 30 checkin. Font support is nearly debugged.
  68. * Make use of glue now.
  69. * Added rational (fraction) types.
  70. *
  71. * Revision 1.3  1993/05/30  21:41:14  richards
  72. * Adding font support to boites.
  73. *
  74. * Revision 1.2  1993/05/23  23:16:47  richards
  75. * Uses the newer X primitives rather than the Self based X code.
  76. *
  77. # Revision 1.1  1993/04/28  22:30:46  richards
  78. # Initial revision
  79. #
  80. *
  81. *
  82. "
  83.  
  84. aa _AddSlotsIfAbsent: (| views* = (). |)
  85. aa views _AddSlotsIfAbsent: (| traits = () |)
  86. aa views _AddSlotsIfAbsent: (| prototypes* = () |)
  87.       
  88. aa views traits _AddSlotsIfAbsent: ( |
  89.     topView      = ().
  90.     equationView = ().
  91.     masterEquationView = ().
  92.     stackEquationView  = ().
  93.     buttonView         = ().
  94. |)
  95.  
  96. aa views prototypes _AddSlotsIfAbsent: (|
  97.     topView      = ().
  98.     equationView = ().
  99.     masterEquationView = ().
  100.     stackEquationView  = ().
  101.     buttonView         = ().
  102. |)
  103.  
  104.  
  105.  
  106. aa views traits topView _Define: (|
  107.     _ parent** = traits compoundView.
  108.     ^ printString = ('AA equation: ', title).
  109.  
  110.     "Window System Parameters"
  111.  
  112.     parameters* = (|
  113.     _ leftMargin  = 5.
  114.     _ topMargin   = 5.
  115.         _ rightMargin = 5.
  116.         _ bottomMargin= 5.
  117.     |).
  118.  
  119.     copying* = (|
  120.     copyUnrealised: sv = (| c. |
  121.         c: resend.copyUnrealised: sv.
  122.         c stackViews: vector copySize: 6 FillingWith: nil.
  123.         c buttons: vector copySize: (aa views editorButtons allButtons size + 1) FillingWith: nil.
  124.         c drawLock: drawLock copy.
  125.         c subViewDo: [|:s|
  126.         s fixUpSuperViewSlots.
  127.         ].
  128.         c
  129.     ).
  130.     |).
  131.     
  132.     "title"
  133.     ^ title = ( iTitle ).
  134.     ^ title: aString = (
  135.     iTitle: aString.
  136.     self
  137.     ).
  138.  
  139.     recalculateSubViewSizes = (
  140.     subViewDo: [|:s| s recalculateSubViewSize. ].
  141.     captionTextPos: 10@((area height) - 20).
  142.     ).
  143.  
  144.     events* = (|
  145.     ^ configureNotify: event = (
  146.         redrawBusy.
  147.         resend.configureNotify: event.
  148.         recalculateSubViewSizes.
  149.         ('top configureNotify area: ',event area printString) printLine.
  150.         redrawUnbusy.
  151.     ).
  152.     ^ expose: event = (
  153.         redraw.
  154.     ).
  155.     |).
  156.  
  157.     drawing* = (|
  158.     clear = (window clear).
  159.     drawAt: p String: s = (
  160.         window drawString: s At: p GC: manager gc
  161.     ).
  162.     drawAt: p String: s InFont: fontStruct = (
  163.         manager gc font: fontStruct fid.
  164.         window drawString: s At: p GC: manager gc.
  165.     ).
  166.     |).
  167.  
  168.     ^ simpleRedraw = (
  169.     'simple redraw' printLine.
  170.     drawAt: captionTextPos String: captionText.
  171.     subViewDo: [|:s| s redraw ].
  172.     ).
  173.  
  174.     ^ redrawBusy = (
  175.     'redrawBusy' printLine.
  176.     drawLock protect: [
  177.         drawBusy: true.
  178.     ].
  179.     ).
  180.  
  181.     ^ redrawUnbusy = (
  182.     'redrawUnbusy' printLine.
  183.     drawLock protect: [
  184.         drawBusy: false.
  185.     ].
  186.     needRedraw ifTrue: [ redraw ].
  187.     ).
  188.         
  189.     ^ redrawProtect: aBlock = (| doRedraw. |
  190.     doRedraw: false.
  191.     drawLock protect: [
  192.         drawBusy ifTrue: [
  193.         needRedraw: true.      " flag that we need a redraw "
  194.         ] False: [    
  195.         drawBusy: true.    " flag that we are busy "
  196.         doRedraw: true.   
  197.         ].
  198.     ].
  199.     doRedraw ifTrue: [
  200.         aBlock value.
  201.         drawLock protect: [
  202.         drawBusy:   false.
  203.         needRedraw: false.
  204.         ].
  205.     ].
  206.     ).
  207.     
  208.     redraw = (
  209.     redrawProtect: [ simpleRedraw ].
  210.     ).
  211.  
  212.     ^ masterEquation = (
  213.     masterEquationView isNil ifFalse: [ masterEquationView equation].
  214.     ).
  215.     ^ masterEquation: eqn = (
  216.     masterEquationView isNil ifFalse: [ masterEquationView equation: eqn. ].
  217.     ).
  218.     ^ stackEquationAt: pos = (
  219.     (stackViews at: pos) equation
  220.     ).
  221.     ^ stackEquationAt: pos Put: eqn = (
  222.     (stackViews at: pos) equation: eqn
  223.     ).
  224.  
  225.     ^ topViewInitialise = (| sv. buttonOrigin. temp. |
  226.     removeSubViews.
  227.     sv: aa masterEquationView copy.
  228.     sv removeSubViews.
  229.     addSubView: sv.
  230.     0 to: 5 Do: [|:sp| 
  231.         sv: aa stackEquationView copy.
  232.         sv removeSubViews.
  233.         sv stackPos: sp.
  234.         addSubView: sv.
  235.     ].
  236.     temp: (area height / 6).
  237.     buttonOrigin: 10@((temp*5) + (temp/3)).
  238.     aa views editorButtons allButtons do: [|:aButton. nb. |
  239.         nb: aButton copy.
  240.         nb translateTo: (buttonOrigin + ((40 * aButton buttonNum)@0)).
  241.         addSubView: nb.
  242.     ]. 
  243.     ).
  244.  
  245.     activeWindowStackSize = 10.
  246.     lastActiveWindow: win = (
  247.     (activeWindowStack size > activeWindowStackSize) ifTrue: [
  248.         activeWindowStack removeLast.
  249.     ].
  250.     activeWindowStack addFirst: win.
  251.     ).
  252.  
  253.     caption: text = (
  254.     clearRectangle: (captionTextPos)#((area width)@20).
  255.     captionText: text.
  256.     drawAt: captionTextPos String: captionText.
  257.     ).
  258.  
  259.     userError: text = (
  260.     text printLine.    "XXX - put window and do graphical error"
  261.     ).
  262.  
  263.     equation: eqn = (
  264.     " XXX - should push the previous one onto the derivation list, and the undo stack "
  265.     ('Setting master equation to: ' , eqn printString) printLine.
  266.     masterEquation: eqn.
  267.     ).
  268. |)
  269.  
  270.  
  271. aa views prototypes topView _Define: compoundView
  272. aa views prototypes topView _AddSlots: (|
  273.     _ parent* = aa views traits topView.
  274.     "_" iArea <- (0@0)##(800@@400).
  275.     "_" iIcon <- 'AlgebraAssistant'.
  276.     "_" masterEquationView.
  277.     "_" stackViews.
  278.     "_" buttons.
  279.     "_" iTitle <- 'Unnamed'.
  280.     ^ titleFontName <- '-*-Courier-*-r-*-*-18-*-*-*-*-*-*-*'.
  281.     "_" titleFont.
  282.     _ drawLock <- semaphore copyBinary.
  283.     _ drawBusy <- false.
  284.     _ needRedraw <- false.
  285.     ^ activeWindowStack <- list copy.  " XXX - should be a stack "
  286.     ^ handlerForNextWindow <- aa editor selectionEventHandler.
  287.     ^ captionText <- 'no help'.
  288.     ^ captionTextPos <- 0@0.
  289.     "_" iEventMask <- xlib events keyPressMask
  290.     || xlib events exposureMask
  291.     || xlib events structureNotifyMask
  292.     || xlib events buttonReleaseMask.
  293.     debugFlag <- false.
  294. |)
  295.  
  296.  
  297. aa views traits equationView _Define: (|
  298.     _ parent** = traits compoundView.
  299.     ^ printString = ('AA equation: ', eqnname).
  300.  
  301.     "Window System Parameters"
  302.  
  303.     parameters* = (|
  304.     _ leftMargin    = 5.
  305.     _ topMargin     = 5.
  306.     _ rightMargin   = 5.
  307.     _ bottomMargin  = 5.
  308.     |).
  309.  
  310.     copying* = (|
  311.     copyUnrealised: sv = (| c. |
  312.         c: resend.copyUnrealised: sv.
  313.         c boiteSubViews: boiteSubViews copyRemoveAll.
  314.         c viewHandler: viewHandler copyForView: c.
  315.         c
  316.     ).
  317.     |).
  318.  
  319.     realisation* = (|
  320.     realise: v = (
  321.         resend.realise: v.
  322.         self).
  323.  
  324.     basicUnrealise = (
  325.         resend.basicUnrealise.
  326.         self
  327.     ).
  328.     
  329.     |).
  330.     
  331.     ^ calculateSubViewSize = (
  332.     error: 'subclass responsability'.
  333.     ).
  334.  
  335.     ^ recalculateSubViewSize = (
  336.     calculateSubViewSize.
  337.     area: area.
  338.     recalculatePosition.
  339.     ).
  340.  
  341.     events* = (|
  342.  
  343.     ^ expose: event = (
  344.         redraw.
  345.         manager flush.
  346.     ).
  347.     
  348.     |).
  349.  
  350.     _ viewEvents* = (|
  351.     ^ enterNotify: event    = (
  352.         (viewHandler handlerName = topView handlerForNextWindow handlerName) ifFalse: [
  353.         viewHandler: topView handlerForNextWindow copyForView: self.
  354.         'handling ' print. self print. ' with ' print. viewHandler printLine.
  355.         ].
  356.         viewHandler enter: (event x)@(event y).
  357.     ).
  358.     ^ selectDown: pt      = ( topView lastActiveWindow: self. viewHandler selectDown: pt ).
  359.     ^ selectUp: pt        = ( topView lastActiveWindow: self. viewHandler selectUp: pt ).
  360.     ^ copyDown: pt        = ( topView lastActiveWindow: self. viewHandler copyDown: pt ).
  361.     ^ copyUp: pt          = ( topView lastActiveWindow: self. viewHandler copyUp: pt ).
  362.     ^ motionNotify: event = ( topView lastActiveWindow: self. viewHandler motion: (event x@event y) ).
  363.     |).
  364.  
  365.     ^ recalculatePosition = (| centerX. centerY. |
  366.     centerX: (area width)/2.
  367.     centerY: (area height)/2.
  368.     equationBoites isNil ifFalse: [ 
  369.         equationOrigin: (centerX - (equationBoites xSize / 2))@centerY.
  370.         equationBBox: ((equationOrigin x)@(centerY - equationBoites posy))##(equationBoites extent).
  371.     ].
  372.     ).
  373.  
  374.     
  375.     ^ simpleRedraw = (
  376.     clear.
  377.     drawInFixedFontAt: 3@10 String: eqnname.
  378.  
  379.     subViewDo: [| :aSv |
  380.         aSv simpleRedraw.
  381.     ].
  382.     ).
  383.  
  384.     ^ redrawProtect: drawBlock = ( superView redrawProtect: drawBlock ).
  385.     
  386.     ^ redraw = (
  387.     superView redrawProtect: [ simpleRedraw ].
  388.     ).
  389.  
  390.     ^ equation = ( iEquation ).
  391.     ^ equation: eqn = (
  392.     iEquation: eqn.
  393.     redrawProtect: [
  394.         equationBoites: eqn makeBoite.
  395.         equationBoites fixUpFonts: self.
  396.         equationBoites makeRequiredSizes.
  397.         recalculatePosition.
  398.         removeSubViews.
  399.         boiteSubViews removeAll.
  400.         equationBoites createLWViewOn: self At: equationOrigin.
  401.     ].
  402.     redraw.
  403.     ).
  404. |)
  405.  
  406. aa views prototypes equationView _Define: compoundView
  407. aa views prototypes equationView _AddSlots: (|
  408.     _ parent* = aa views traits equationView.
  409.     "_" eqnname <- 'unnamed'.
  410.     "_" iEquation.
  411.     "_" equationBoites.
  412.     "_" equationBBox <- (0@0)##(0@@0).
  413.     "_" equationOrigin <- 0@0.
  414.     ^ viewHandler <- aa editor selectionEventHandler copy.
  415.     "_" boiteSubViews <- dictionary copy.
  416.     "_" areaSelect.
  417.     "_" iEventMask <- xlib events keyPressMask
  418.       || xlib events exposureMask
  419.       || xlib events buttonPressMask
  420.       || xlib events buttonReleaseMask
  421.       || xlib events enterWindowMask.
  422.     debugFlag <- false.
  423. |)
  424.  
  425. aa views traits masterEquationView _Define: (|
  426.     _ parent* = aa views traits equationView.
  427.     ^ calculateSubViewSize = ( | xSize. ySize. |
  428.     xSize: superView area width.
  429.     ySize: superView area height.
  430.     iArea: (leftMargin@topMargin)##((2*((xSize/3)-leftMargin))@@(((5*ySize)/6)-(2*topMargin))).
  431.     ).
  432.     
  433.     ^ fixUpSuperViewSlots = (
  434.     superView masterEquationView: self.
  435.     )
  436. |)  
  437.  
  438. aa views prototypes masterEquationView _Define: aa views prototypes equationView
  439. aa views prototypes masterEquationView _AddSlots: (|
  440.     ^ parent* = aa views traits masterEquationView.
  441.     "_" eqnname <- 'master: unnamed'.
  442. |)
  443.  
  444. aa views traits stackEquationView _Define: (|
  445.     _ parent** = aa views traits equationView.
  446.     ^ calculateSubViewSize = ( | xSize. ySize. width3. height6. |
  447.     xSize: superView area width.
  448.     ySize: superView area height.
  449.     width3: xSize / 3.
  450.     height6: ySize / 6.
  451.     iArea: (((2*width3)+leftMargin)@((stackPos*height6)+topMargin))#
  452.           ((xSize - rightMargin)@(((stackPos+1)*height6)-bottomMargin)).
  453.     ).
  454.     ^ fixUpSuperViewSlots = (
  455.     superView stackViews at: stackPos Put: self.
  456.     ).
  457. |)
  458.  
  459. aa views prototypes stackEquationView _Define: aa views prototypes equationView
  460. aa views prototypes stackEquationView _AddSlots: (|
  461.     ^ parent* = aa views traits stackEquationView.
  462.     "_" eqnname <- 'stack: unnamed'.
  463.     stackPos <- 1.
  464. |)
  465.  
  466.  
  467.  
  468.