G.1.4 les méthodes de lancement

Calculatrice>>creeCalcButton: tabEtiquette  
                         for: tabSelecteur  
                         and: tabActivF  
                       frame: rects  
                      window: window  
                        etat: etats  
   | view collection vues |  
   tabEtiquette  
      with: tabSelecteur  
      and: tabActivF  
      and: rects  
      and: etats  
      do: [:touches :funs :fonc :rect :mesEtats |  
         | m bouton |  
         collection := OrderedCollection new.  
         vues := OrderedCollection new.  
         m := AlignmentMorph newRow.  
         touches  
            with: funs  
            and: mesEtats  
            do: [:touche :fun :eta |  
               view :=  
                  (self newCalcButton: (bouton := fun == #autreBase  
                      ifTrue: [CalcButtonEtiquetteVariable new  
                                       label: fun  
                                       fonction: fonc  
                                       etat: eta  
                                       on: self]  
                       ifFalse: [CalcButton new  
                                       label: fun  
                                       fonction: fonc  
                                       etat: eta  
                                       on: self]))  
               vues addFirst: view.  
               self addDependent: bouton.  
               collection addFirst: bouton].  
         CalcButton initialise: collection.  
         vues  
            do: [:tView | m addMorph: tView].  
         window addMorph: m frame: rect]
Calculatrice>>creeTouches: tabEtiquette  
                     with: tabSelecteur  
                      and: tabMorphs  
                 function: tabActivF  
                    frame: rects  
                   window: window  
   | view a1 r |  
    tabEtiquette with: tabSelecteur  
                  and: tabMorphs  
                  and: tabActivF  
                  and: rects  
      do: [:touches :funs :m :foncs :rect |  
            touches with: foncs and: funs do:  
            [:touche  :fonc :fun  |  
             r:= rect.  
               view := (self  
                        newTouche: fun  
                        avec: fonc)  
                        with: window color  
                        and: touche.  
               m addMorphBack: view. a1 := m].  
         window  
            addMorph:a1  
            frame: r].
Calculatrice>>newCalcButton: aFunction  
newCalcButton: aFunction  
   ^ (aFunction isKindOf: CalcButtonEtiquetteVariable)  
        ifTrue: [PluggableButtonMorph  
                   on: aFunction  
                   getState: #etat  
                   action: #activer  
                   label: #changeEtiquette  
                   menu: nil]  
        ifFalse: [PluggableButtonMorph  
                   on: aFunction  
                   getState: #etat  
                   action: #activer]
Calculatrice>>newTouche: co avec: fonction  
   | morph touche |  
   morph := PluggableButtonMorph  
            on: (touche := Touche new  
                  label: co  
                  fonction: fonction  
                  on: self)  
            getState: #etat  
            action: #activer.  
   (co isSymbol not and: [co size < 2]  
      and: [((co at: 1) digitValue between: 0 and: 15)])  
            ifTrue:  
               [AllTouchesNumeriques at: (co at: 1) digitValue + 1  
                                    put: touche].  
   ^morph
Calculatrice>>openInWorld  
   | window view |  
   window := SystemWindow labelled: self class name.  
   view := PluggableTextMorph  
            on: self  
            text: #printString  
            accept: nil.  
   view  
      font: (StrikeFont familyName: ’Atlanta’ size: 22).  
   window  
      addMorph: view  
      frame: (2 / 5 @ 0 extent: 3 / 5 @ (1 / 5)).  
   self creeCalcButton: #(#(’Hex’ ’Dec’ ’Oct’ ’Bin’ ’autre’)  
                          #(’Deg’ ’Rad’ ’Gra’) )  
         for:  
                  #(#(#Hex #Dec #Oct #Bin #autreBase)  
                    #(#Deg #Rad #Gra) )  
         and:  
                    #(#activeBase: #activeAngle:)  
         frame:  
                  {0 @ 0 extent: 2 / 5 @ (1 / 10).  
                  0 @ (1 / 10) extent: 2 / 5 @ (1 / 10). }  
         window: window  
         etat: #(#(false true false false false)  
                 #(true false false)).  
   self  
      creeTouches: #(  
                  #(’log(y)’ ’Sin’ ’Cos’ ’Tan’ ’Log’ ’Ln’)  
                  #(’sqrt’ ’+/-’ ’1/x’ ’x!’ ’x^2’ ’x^y’)  
                  #(’A’ ’B’ ’C’ ’D’ ’E’ ’F’)  
                  #(’M-’ ’7’ ’4’ ’1’ ’0’)  
                  #(’MR’ ’8’ ’5’ ’2’ ’.’)  
                  #(’M+’ ’9’ ’6’ ’3’ ’=’)  
                  #(’MC’ ’(’ ’x’ ’+’ ’%’)  
                  #(’CE’ ’)’ ’/’ ’-’ ’Const’)  
                  #(’Ac’ ’And’ ’Or’ ’L/Rsh’ ’Mod’))  
      with: #(  
            #(log: Sin Cos Tan log ln)  
             #(sqrt negated inv factorial squared raisedTo:)  
            #(’A’ ’B’ ’C’ ’D’ ’E’ ’F’)  
             #(memSub’7’ ’4’ ’1’ ’0’)  
            #(memRead ’8’ ’5’ ’2’ ’.’)  
            #(memPlus ’9’ ’6’ ’3’ ’=’)  
            #(memClear ’(’ * + percent)  
            #(’CE’ ’)’ div: - ’Const’)  
            #(’Ac’ bitAnd: bitOr: bitShift: \\))  
      and: {AlignmentMorph newColumn. AlignmentMorph newColumn.  
            AlignmentMorph newColumn. AlignmentMorph newColumn.  
            AlignmentMorph newColumn. AlignmentMorph newColumn.  
            AlignmentMorph newColumn. AlignmentMorph newColumn.  
            AlignmentMorph newColumn. }
      function: #(  
               #(activeFonction: activeTrigo: activeTrigo:  
                 activeTrigo: #activeFonctionUnaire:  
                 #activeFonctionUnaire:)  
               #(activeFonctionUnaire: activeFonctionUnaire:  
                 activeFonctionUnaire: activeFonctionUnaire:  
                 activeFonctionUnaire: #activeFonction: )  
               #(activeNumber: activeNumber: activeNumber:  
                 activeNumber: activeNumber: activeNumber:)  
               #(#activeMem: #activeNumber: #activeNumber:  
                 #activeNumber: #activeNumber:)  
               #(#activeMem: #activeNumber: #activeNumber:  
                 #activeNumber: #activeNumberPoint:)  
               #(#activeMem: #activeNumber: #activeNumber:  
                 #activeNumber: #activeEgal:)  
               #(activeMem: activeOuvrante: activeFonction:  
                 activeFonction: activeFonction:)  
               #(activeClearEcran: activeFermante: activeFonction:  
                 activeFonction: activeConstante:)  
               #(activeClear: activeFonction: activeFonction:  
                 activeFonction: activeFonction:))  
      frame: {  
            0 @ (1 / 5) extent: 2 / 15 @ (4 / 5).  
            2/15 @ (1/5) extent: 2/15 @ (4/5).  
            4/15 @ (1/5) extent: 2/15 @ (4/5).  
            6 / 15 @ (1 / 5) extent: 1 / 10 @ (4 / 5).  
            5 / 10 @ (1 /5) extent: 1 / 10 @(4 / 5).  
            6 / 10 @ (1 /5) extent: 1 / 10 @(4 / 5).  
            7 / 10 @ (1 /5) extent: 1 / 10 @(4 / 5).  
            8 / 10 @ (1 /5) extent: 1 / 10 @(4 / 5).  
            9 / 10 @ (1 /5) extent: 1 / 10 @(4 / 5).}  
      window: window.  
   self initTouches.  
   window openInWorld