Exemple #1
0
void TTable::handleEvent(TEvent& event) {
    TView::handleEvent(event);

    if (event.what == evMouseDown) {
        do {
            if (mouseInView(event.mouse.where)) {
                TPoint spot = makeLocal(event.mouse.where);
                setCursor(spot.x, spot.y);
                charFocused();
            }
        } while (mouseEvent(event, evMouseMove));
        clearEvent(event);
    } else {
        if (event.what == evKeyboard) {
            switch (event.keyDown.keyCode) {
            case kbHome:
                setCursor(0, 0);
                break;
            case kbEnd:
                setCursor(size.x - 1, size.y - 1);
                break;
            case kbUp:
                if (cursor.y > 0)
                    setCursor(cursor.x, cursor.y - 1);
                break;
            case kbDown:
                if (cursor.y < size.y - 1)
                    setCursor(cursor.x, cursor.y + 1);
                break;
            case kbLeft:
                if (cursor.x > 0)
                    setCursor(cursor.x - 1, cursor.y);
                break;
            case kbRight:
                if (cursor.x < size.x - 1)
                    setCursor(cursor.x + 1, cursor.y);
                break;
            default:
                setCursor(event.keyDown.charScan.charCode % 32,
                        event.keyDown.charScan.charCode / 32);
                break;
            }
            charFocused();
            clearEvent(event);
        }
    }
}
void TColorSelector::handleEvent(TEvent &event) {
   const int width = 4;

   TView::handleEvent(event);

   uchar oldColor = color;
   int maxCol = (selType == csBackground) ? 7 : 15;
   switch (event.what) {

   case evMouseDown:
      do  {
         if (mouseInView(event.mouse.where)) {
            TPoint mouse = makeLocal(event.mouse.where);
            color = mouse.y * 4 + mouse.x / 3;
         } else
            color = oldColor;
         colorChanged();
         drawView();
      } while (mouseEvent(event, evMouseMove));
      break;

   case evKeyDown:
      switch (ctrlToArrow(event.keyDown.keyCode)) {
      case kbLeft:
         if (color > 0)
            color--;
         else
            color = maxCol;
         break;

      case kbRight:
         if (color < maxCol)
            color++;
         else
            color = 0;
         break;

      case kbUp:
         if (color > width - 1)
            color -= width;
         else if (color == 0)
            color = maxCol;
         else
            color += maxCol - width;
         break;

      case kbDown:
         if (color < maxCol - (width - 1))
            color += width;
         else if (color == maxCol)
            color = 0;
         else
            color -= maxCol - width;
         break;

      default:
         return;
      }
      break;

   case evBroadcast:
      if (event.message.command == cmColorSet) {
         if (selType == csBackground)
            color = event.message.infoByte >> 4;
         else
            color = event.message.infoByte & 0x0F;
         drawView();
         return ;
      } else
         return;
void TListViewer::handleEvent(TEvent &event) {
   TPoint mouse;
   ushort colWidth;
   int oldItem, newItem;
   int count;
   int mouseAutosToSkip = 4;

   TView::handleEvent(event);

   if (event.what == evMouseDown) {
      colWidth = size.x / numCols + 1;
      oldItem =  focused;
      mouse = makeLocal(event.mouse.where);
      if (mouseInView(event.mouse.where))
         newItem = mouse.y + (size.y * (mouse.x / colWidth)) + topItem;
      else
         newItem = oldItem;
      count = 0;
      do  {
         if (newItem != oldItem) {
            focusItemNum(newItem);
            drawView();
         }
         oldItem = newItem;
         mouse = makeLocal(event.mouse.where);
         if (mouseInView(event.mouse.where))
            newItem = mouse.y + (size.y * (mouse.x / colWidth)) + topItem;
         else {
            if (numCols == 1) {
               if (event.what == evMouseAuto)
                  count++;
               if (count == mouseAutosToSkip) {
                  count = 0;
                  if (mouse.y < 0)
                     newItem = focused - 1;
                  else if (mouse.y >= size.y)
                     newItem = focused + 1;
               }
            } else {
               if (event.what == evMouseAuto)
                  count++;
               if (count == mouseAutosToSkip) {
                  count = 0;
                  if (mouse.x < 0)
                     newItem = focused - size.y;
                  else if (mouse.x >= size.x)
                     newItem = focused + size.y;
                  else if (mouse.y < 0)
                     newItem = focused - focused % size.y;
                  else if (mouse.y > size.y)
                     newItem = focused - focused % size.y + size.y - 1;
               }
            }
         }
         if (event.mouse.eventFlags & meDoubleClick)
            break;
      } while (mouseEvent(event, evMouseMove | evMouseAuto));
      focusItemNum(newItem);
      drawView();
      if ((event.mouse.eventFlags & meDoubleClick) && range > newItem)
         selectItem(newItem);
      clearEvent(event);
   } else if (event.what == evKeyDown) {
      if (event.keyDown.charScan.charCode ==  ' ' && focused < range) {
         selectItem(focused);
         newItem = focused;
      } else {
         switch (ctrlToArrow(event.keyDown.keyCode)) {
            case kbUp:
               newItem = focused - 1;
               break;
            case kbDown:
               newItem = focused + 1;
               break;
            case kbRight:
               if (numCols > 1)
                  newItem = focused + size.y;
               else
                  return;
               break;
            case kbLeft:
               if (numCols > 1)
                  newItem = focused - size.y;
               else
                  return;
               break;
            case kbPgDn:
               newItem = focused + size.y * numCols;
               break;
            case  kbPgUp:
               newItem = focused - size.y * numCols;
               break;
            case kbHome:
               newItem = topItem;
               break;
            case kbEnd:
               newItem = topItem + (size.y * numCols) - 1;
               break;
            case kbCtrlPgDn:
               newItem = range - 1;
               break;
            case kbCtrlPgUp:
               newItem = 0;
               break;
            default:
               return;
         }
      }
      focusItemNum(newItem);
      drawView();
      clearEvent(event);
   } else if (event.what == evBroadcast) {
      if ((options & ofSelectable) != 0) {
         if (event.message.command == cmScrollBarClicked &&
            (event.message.infoPtr == hScrollBar ||
               event.message.infoPtr == vScrollBar))
                  focus();        // BUG FIX                  <<------ Change
         else 
         if (event.message.command == cmScrollBarChanged) {
            if (vScrollBar == event.message.infoPtr) {
               focusItemNum(vScrollBar->value);
               drawView();
            } else if (hScrollBar == event.message.infoPtr)
               drawView();
         }
      }
   }
}
void TOutlineViewer::handleEvent(TEvent &event) {
   const int mouseAutoToSkip = 3;

   TPoint mouse;
   TNode *cur;
   int newFocus;
   int count;
   char *graph;
   uchar dragged;

   TScroller::handleEvent(event);
   switch (event.what) {
   case evMouseDown:
      count = 0;
      dragged = 0;
      do {
         if (dragged < 2)
            dragged++;
         mouse = makeLocal(event.mouse.where);
         if (mouseInView(event.mouse.where))
            newFocus = delta.y + mouse.y;
         else {
            if (event.what == evMouseAuto)
               count++;
            if (count == mouseAutoToSkip) {
               count = 0;
               if (mouse.y < 0)
                  newFocus--;
               if (mouse.y >= size.y)
                  newFocus++;
            }
         }
         if (foc != newFocus) {
            adjustFocus(newFocus);
            drawView();
         }
      } while (!(event.mouse.eventFlags & meDoubleClick) &&
               mouseEvent(event, evMouseMove + evMouseAuto));

      if (event.mouse.eventFlags & meDoubleClick)
         selected(foc);
      else {
         if (dragged < 2) {
            cur = firstThat(isFocused);
            graph = getGraph(focLevel, focLines, focFlags);
            if (mouse.x < strlen(graph)) {
               adjust(cur, ! isExpanded(cur) ? True : False);
               update();
               drawView();
            }
            delete graph;
         }
      }

      break;

   case evKeyboard:

      newFocus = foc;
      switch (ctrlToArrow(event.keyDown.keyCode)) {
      case kbUp:
      case kbLeft:
         newFocus--;
         break;
      case kbDown:
      case kbRight:
         newFocus++;
         break;
      case kbPgDn:
         newFocus += size.y - 1;
         break;
      case kbPgUp:
         newFocus -= size.y - 1;
         break;
      case kbHome:
         newFocus = delta.y;
         break;
      case kbEnd:
         newFocus = delta.y + size.y - 1;
         break;
      case kbCtrlPgUp:
         newFocus = 0;
         break;
      case kbCtrlPgDn:
         newFocus = limit.y - 1;
         break;
      case kbCtrlEnter:
      case kbEnter:
         selected(newFocus);
         break;
      default:
         uchar code = event.keyDown.charScan.charCode;
         switch (code) {
         case '-':
         case '+':
            adjust(getNode(newFocus), code == '+' ? True : False);
            break;
         case '*':
            expandAll(getNode(newFocus));
            break;
         default:
            return;
         }
         update();
      }
      clearEvent(event);
      adjustFocus(newFocus);
      drawView();
   };
};
ushort TMenuView::execute()
{
    Boolean    autoSelect = False;
    menuAction action;
    char   ch;
    ushort result = 0;
    TMenuItem *itemShown = 0;
    TMenuItem *p;
    TMenuView *target;
    TRect  r;
    TEvent e;

    current = menu->deflt;
    do  {
        action = doNothing;
        getEvent(e);
        switch (e.what)
            {
            case  evMouseDown:
                if( mouseInView(e.mouse.where) || mouseInOwner(e) )
                    {
                    trackMouse(e);
                    if( size.y == 1 )
                        autoSelect = True;
                    }
                else
                    action =  doReturn;
                break;
            case  evMouseUp:
                trackMouse(e);
                if( mouseInOwner(e) )
                    current = menu->deflt;
                else if( current != 0 && current->name != 0 )
                    action = doSelect;
                else
                    action = doReturn;
                break;
            case  evMouseMove:
                if( e.mouse.buttons != 0 )
                    {
                    trackMouse(e);
                    if( !(mouseInView(e.mouse.where) || mouseInOwner(e)) &&
                        mouseInMenus(e) )
                        action = doReturn;
                    }
                break;
            case  evKeyDown:
                switch( ctrlToArrow(e.keyDown.keyCode) )
                    {
                    case  kbUp:
                    case  kbDown:
                        if( size.y != 1 )
                            trackKey(Boolean(ctrlToArrow(e.keyDown.keyCode) == kbDown));
                        else if( e.keyDown.keyCode == kbDown )
                            autoSelect =  True;
                        break;
                    case  kbLeft:
                    case  kbRight:
                        if( parentMenu == 0 )
                            trackKey(Boolean(ctrlToArrow(e.keyDown.keyCode) == kbRight));
                        else
                            action =  doReturn;
                        break;
                    case  kbHome:
                    case  kbEnd:
                        if( size.y != 1 )
                            {
                            current = menu->items;
                            if( e.keyDown.keyCode == kbEnd )
                                trackKey(False);
                            }
                        break;
                    case  kbEnter:
                        if( size.y == 1 )
                            autoSelect =  True;
                        action = doSelect;
                        break;
                    case  kbEsc:
                        action = doReturn;
                        if( parentMenu == 0 || parentMenu->size.y != 1 )
                            clearEvent(e);
                        break;
                    default:
                        target = this;
                        ch = getAltChar(e.keyDown.keyCode);
                        if( ch == 0 )
                            ch = e.keyDown.charScan.charCode;
                        else
                            target = topMenu();
                        p = target->findItem(ch);
                        if( p == 0 )
                            {
                            p = topMenu()->hotKey(e.keyDown.keyCode);
                            if( p != 0 && commandEnabled(p->command) )
                                {
                                result = p->command;
                                action = doReturn;
                                }
                            }
                        else if( target == this )
                            {
                            if( size.y == 1 )
                                autoSelect = True;
                            action = doSelect;
                            current = p;
                            }
                        else if( parentMenu != target ||
                                 parentMenu->current != p )
                                action = doReturn;
                    }
                break;
            case  evCommand:
                if( e.message.command == cmMenu )
                    {
                    autoSelect = False;
                    if (parentMenu != 0 )
                        action = doReturn;
                    }
                else
                    action = doReturn;
                break;
            }

        if( itemShown != current )
            {
            itemShown =  current;
            drawView();
            }

        if( (action == doSelect || (action == doNothing && autoSelect)) &&
            current != 0 &&
            current->name != 0 )
                if( current->command == 0 )
                    {
                    if( (e.what & (evMouseDown | evMouseMove)) != 0 )
                        putEvent(e);
                    r = getItemRect( current );
                    r.a.x = r.a.x + origin.x;
                    r.a.y = r.b.y + origin.y;
                    r.b = owner->size;
                    if( size.y == 1 )
                        r.a.x--;
                    target = topMenu()->newSubView(r, current->subMenu,this);
                    result = owner->execView(target);
                    destroy( target );
                    }
                else if( action == doSelect )
                    result = current->command;

        if( result != 0 && commandEnabled(result) )
            {
            action =  doReturn;
            clearEvent(e);
            }
        } while( action != doReturn );

    if( e.what != evNothing &&
        (parentMenu != 0 || e.what == evCommand))
            putEvent(e);
    if( current != 0 )
        {
        menu->deflt = current;
        current = 0;
        drawView();
        }
    return result;
}