Beispiel #1
0
static gboolean
swatch_button_press (GtkWidget      *widget,
                     GdkEventButton *event)
{
  GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);

  gtk_widget_grab_focus (widget);

  if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
      swatch->priv->has_color)
    {
      do_popup (widget, event);
      return TRUE;
    }
  else if (event->type == GDK_2BUTTON_PRESS &&
           event->button == GDK_BUTTON_PRIMARY)
    {
      g_signal_emit (swatch, signals[ACTIVATE], 0);
      return TRUE;
    }
  else if (event->button == GDK_BUTTON_PRIMARY)
    {
      return TRUE;
    }

  return FALSE;
}
Beispiel #2
0
static void
hold_action (GtkGestureLongPress *gesture,
             gdouble              x,
             gdouble              y,
             GtkColorSwatch      *swatch)
{
    do_popup (swatch);
    gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
}
Beispiel #3
0
SDL_bool load_keyboard_mapping( struct machine *oric, char *filename )
{
    SDL_bool ok = SDL_TRUE;
    FILE *f = NULL;
    char buf[4096];
    int host_key, oric_key;

    f = fopen(filename, "rt");
    if (!f)
    {
        msgbox(oric, MSGBOX_OK, "Unable to read keyboard mapping file (1)");
        return SDL_FALSE;
    }

    // first reset the mapping
    reset_keyboard_mapping(&(oric->keyboard_mapping));

    // while we are not finished reading the file
    while (!feof(f) && !ferror(f)) {
        // if we can read something
        if (fgets(buf, 4096, f)>0) {
            // if it's not a comment
            if (buf[0] != '#') {
                // if we can read a definition
                if (sscanf(buf, "%d : %d", &host_key, &oric_key)==2) {
                    // add it to the keyboard mapping
                    add_to_keyboard_mapping( &(oric->keyboard_mapping), host_key, oric_key);
                }
            }
        }
    }

    if(ferror(f)) {
        msgbox(oric, MSGBOX_OK, "Problem while reading from keyboard mapping file (2)");
        return SDL_FALSE;
    }

    if (sprintf(buf, "Read %d key mappings", oric->keyboard_mapping.nb_map) > 0)
        do_popup(oric, buf);

    if(fclose(f) == EOF) {
        msgbox(oric, MSGBOX_OK, "Unable to close keyboard mapping file (3)");
        return SDL_FALSE;
    }

    return ok;
}
Beispiel #4
0
static void
tap_action (GtkGestureMultiPress *gesture,
            gint                  n_press,
            gdouble               x,
            gdouble               y,
            GtkColorSwatch       *swatch)
{
    guint button;

    button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));

    if (button == GDK_BUTTON_PRIMARY)
    {
        if (n_press == 1)
            swatch_primary_action (swatch);
        else if (n_press > 1)
            g_signal_emit (swatch, signals[ACTIVATE], 0);
    }
    else if (button == GDK_BUTTON_SECONDARY)
    {
        if (swatch->priv->has_color && swatch->priv->has_menu)
            do_popup (swatch);
    }
}
Beispiel #5
0
/*! \todo Finish function documentation!!!
 *  \brief
 *  \par Function Description
 *
 */
gint
x_event_button_pressed(GschemPageView *page_view, GdkEventButton *event, GschemToplevel *w_current)
{
  PAGE *page = gschem_page_view_get_page (page_view);
  int w_x, w_y;
  int unsnapped_wx, unsnapped_wy;

  g_return_val_if_fail ((w_current != NULL), 0);

  if (page == NULL) {
    return TRUE; /* terminate event */
  }

  if (!gtk_widget_has_focus (GTK_WIDGET (page_view))) {
    gtk_widget_grab_focus (GTK_WIDGET (page_view));
  }

  scm_dynwind_begin ((scm_t_dynwind_flags) 0);
  g_dynwind_window (w_current);

#if DEBUG
  printf("pressed button %d! \n", event->button);
  printf("event state: %d \n", event->state);
  printf("w_current state: %d \n", w_current->event_state);
  printf("Selection is:\n");
  o_selection_print_all(&(page->selection_list));
  printf("\n");
#endif

  gschem_page_view_SCREENtoWORLD (page_view, (int) event->x, (int) event->y,
                                  &unsnapped_wx, &unsnapped_wy);
  w_x = snap_grid (w_current, unsnapped_wx);
  w_y = snap_grid (w_current, unsnapped_wy);

  if (event->type == GDK_2BUTTON_PRESS &&
      w_current->event_state == SELECT) {
    /* Don't re-select an object (lp-912978) */
    /* o_find_object(w_current, w_x, w_y, TRUE); */

    /* GDK_BUTTON_EVENT is emitted before GDK_2BUTTON_EVENT, which
     * leads to setting of the inside_action flag.  If o_edit()
     * brings up a modal window (e.g., the edit attribute dialog),
     * it intercepts the release button event and thus doesn't
     * allow resetting of the inside_action flag so we do it
     * manually here before processing the double-click event. */
    i_action_stop (w_current);
    o_edit(w_current, geda_list_get_glist( page->selection_list ));
    scm_dynwind_end ();
    return(0);
  }

  w_current->SHIFTKEY   = (event->state & GDK_SHIFT_MASK  ) ? 1 : 0;
  w_current->CONTROLKEY = (event->state & GDK_CONTROL_MASK) ? 1 : 0;
  w_current->ALTKEY     = (event->state & GDK_MOD1_MASK) ? 1 : 0;

  /* Huge switch statement to evaluate state transitions. Jump to
   * end_button_pressed label to escape the state evaluation rather than
   * returning from the function directly. */

  if (event->button == 1) {
    if (w_current->inside_action) {
      /* End action */
      if (page->place_list != NULL) {
        switch(w_current->event_state) {
          case (COMPMODE)   : o_place_end(w_current, w_x, w_y, w_current->continue_component_place,
                                "%add-objects-hook"); break;
          case (TEXTMODE)   : o_place_end(w_current, w_x, w_y, FALSE,
                                "%add-objects-hook"); break;
          case (PASTEMODE)  : o_place_end(w_current, w_x, w_y, FALSE,
                                "%paste-objects-hook"); break;
          default: break;
        }
      } else {
        switch(w_current->event_state) {
          case (ARCMODE)    : o_arc_end1(w_current, w_x, w_y); break;
          case (BOXMODE)    : o_box_end(w_current, w_x, w_y); break;
          case (BUSMODE)    : o_bus_end(w_current, w_x, w_y); break;
          case (CIRCLEMODE) : o_circle_end(w_current, w_x, w_y); break;
          case (LINEMODE)   : o_line_end(w_current, w_x, w_y); break;
          case (NETMODE)    : o_net_end(w_current, w_x, w_y); break;
          case (PATHMODE)   : o_path_continue (w_current, w_x, w_y); break;
          case (PICTUREMODE): o_picture_end(w_current, w_x, w_y); break;
          case (PINMODE)    : o_pin_end (w_current, w_x, w_y); break;
          default: break;
        }
      }
    } else {
      /* Start action */
      switch(w_current->event_state) {
        case (ARCMODE)    : o_arc_start(w_current, w_x, w_y); break;
        case (BOXMODE)    : o_box_start(w_current, w_x, w_y); break;
        case (BUSMODE)    : o_bus_start(w_current, w_x, w_y); break;
        case (CIRCLEMODE) : o_circle_start(w_current, w_x, w_y); break;
        case (LINEMODE)   : o_line_start(w_current, w_x, w_y); break;
        case (NETMODE)    : o_net_start(w_current, w_x, w_y); break;
        case (PATHMODE)   : o_path_start (w_current, w_x, w_y); break;
        case (PICTUREMODE): o_picture_start(w_current, w_x, w_y); break;
        case (PINMODE)    : o_pin_start (w_current, w_x, w_y); break;
        case (ZOOMBOX)    : a_zoom_box_start(w_current, unsnapped_wx, unsnapped_wy); break;
        case (SELECT)     : o_select_start(w_current, w_x, w_y); break;

        case (COPYMODE)   :
        case (MCOPYMODE)  : o_copy_start(w_current, w_x, w_y); break;
        case (MOVEMODE)   : o_move_start(w_current, w_x, w_y); break;
        default: break;
      }
    }

    switch(w_current->event_state) {
      case(ROTATEMODE):   o_rotate_world_update(w_current, w_x, w_y, 90,
                            geda_list_get_glist(page->selection_list)); break;
      case(MIRRORMODE):   o_mirror_world_update(w_current, w_x, w_y,
                            geda_list_get_glist(page->selection_list)); break;

      case(PAN):
        gschem_page_view_pan (page_view, w_x, w_y);
        i_set_state(w_current, SELECT);
        break;
    }
  } else if (event->button == 2) {

    /* try this out and see how it behaves */
    if (w_current->inside_action) {
      if (!(w_current->event_state == COMPMODE||
            w_current->event_state == TEXTMODE||
            w_current->event_state == MOVEMODE||
            w_current->event_state == COPYMODE  ||
            w_current->event_state == MCOPYMODE ||
            w_current->event_state == PASTEMODE )) {
        i_callback_cancel(w_current, 0, NULL);
      }
      goto end_button_pressed;
    }

    switch(w_current->middle_button) {

      case(ACTION):

      /* don't want to search if shift */
      /* key is pressed */
      if (!w_current->SHIFTKEY) {
        o_find_object(w_current, unsnapped_wx, unsnapped_wy, TRUE);
      }

      /* make sure the list is not empty */
      if (!o_select_selected(w_current)) {
        /* this means the above find did not
         * find anything */
        i_action_stop (w_current);
        i_set_state(w_current, SELECT);
        goto end_button_pressed;
      }

      /* determine here if copy or move */
      if (w_current->ALTKEY) {
        i_set_state(w_current, COPYMODE);
        o_copy_start(w_current, w_x, w_y);
      } else {
        o_move_start(w_current, w_x, w_y);
      }
      break;

      case(REPEAT):
      if (w_current->last_callback != NULL) {
        (*w_current->last_callback)(w_current, 0, NULL);
      }
      break;
#ifdef HAVE_LIBSTROKE
      case(STROKE):
      DOING_STROKE=TRUE;
      break;
#endif /* HAVE_LIBSTROKE */

      case(MID_MOUSEPAN_ENABLED):
      gschem_page_view_pan_start (page_view, (int) event->x, (int) event->y);
      break;
    }

  } else if (event->button == 3) {
    if (!w_current->inside_action) {
      if (w_current->third_button == POPUP_ENABLED) {
        /* (third-button "popup") */
        i_update_menus(w_current);  /* update menus before popup  */
        do_popup(w_current, event);
      } else {
        /* (third-button "mousepan") */
        gschem_page_view_pan_start (page_view, (int) event->x, (int) event->y);
      }
    } else {
      if ((w_current->third_button == MOUSEPAN_ENABLED) &&
          (!w_current->third_button_cancel)) {
        gschem_page_view_pan_start (page_view, (int) event->x, (int) event->y);
      } else { /* this is the default cancel */

        /* reset all draw and place actions */

        switch (w_current->event_state) {

          case (ARCMODE)    : o_arc_invalidate_rubber     (w_current); break;
          case (BOXMODE)    : o_box_invalidate_rubber     (w_current); break;
          case (BUSMODE)    : o_bus_invalidate_rubber     (w_current); break;
          case (CIRCLEMODE) : o_circle_invalidate_rubber  (w_current); break;
          case (LINEMODE)   : o_line_invalidate_rubber    (w_current); break;
          case (NETMODE)    : o_net_reset                 (w_current); break;
          case (PATHMODE)   : o_path_invalidate_rubber    (w_current); break;
          case (PICTUREMODE): o_picture_invalidate_rubber (w_current); break;
          case (PINMODE)    : o_pin_invalidate_rubber     (w_current); break;

          default:
            i_callback_cancel(w_current, 0, NULL);
            break;
        }
      }
    }
  }

 end_button_pressed:
  scm_dynwind_end ();

  return(0);
}
Beispiel #6
0
static gboolean
swatch_popup_menu (GtkWidget *widget)
{
    do_popup (GTK_COLOR_SWATCH (widget));
    return TRUE;
}
Beispiel #7
0
static gboolean
swatch_popup_menu (GtkWidget *swatch)
{
  do_popup (swatch, 0, gtk_get_current_event_time ());
  return TRUE;
}
Beispiel #8
0
// This is the event handler for when you are in the menus
SDL_bool keyboard_event( SDL_Event *ev, struct machine *oric, SDL_bool *needrender )
{
    SDL_bool done = SDL_FALSE;
    SDL_bool lshifted = modKeyPressed[MOD_LSHIFT];
    SDL_bool rshifted = modKeyPressed[MOD_RSHIFT];

    int i, x, y, current_key_num = -1;
    static char tmp[64];
    struct kbdkey * kbd;

    if (release_keys)
    {
      x = 0;
      for (i=0; i<modKeyMax; i++)
      {
        if (modKeyPressed[i])
        {
          modKeyPressed[i] = SDL_FALSE;
          ay_keypress( &oric->ay, modKeys[i], SDL_FALSE );
          snprintf(tmp, sizeof(tmp), "%s released.", modKeyNames[i]);
          do_popup(oric, tmp);
          x++;
        } else if (modKeyFakePressed[i]) {
          modKeyFakePressed[i] = SDL_FALSE;
          ay_keypress( &oric->ay, modKeys[i], SDL_FALSE );
        }
      }

      if (x > 1)
        do_popup(oric, "All keys released");

      release_keys = SDL_FALSE;
    }

    x = -1;
    y = -1;
    switch( ev->type )
    {
        case SDL_MOUSEBUTTONDOWN:
            x = ev->button.x;
            y = ev->button.y - 480;

            switch( oric->type )
            {
                case MACH_PRAVETZ:
                    kbd = kbd_pravetz;
                    break;
                case MACH_ORIC1:
                case MACH_ORIC1_16K:
                    kbd = kbd_oric1;
                    break;
                default:
                    kbd = kbd_atmos;
                    break;
            }

            // find the visual key under the mouse pointer
            current_key = NULL;
            for(i=0; i<62; i++) {
                if ((x > kbd[i].x) && (x < kbd[i].x + kbd[i].w) &&
                    (y > kbd[i].y) && (y < kbd[i].y + kbd[i].h)) {
                    current_key = &(kbd[i]);
                    current_key_num = i;
                    //if (ev->type == SDL_MOUSEBUTTONDOWN)
                    //   printf("Key %d pressed : keysim %d (%c)\n",
                    //          i, current_key->keysim, (char)(current_key->keysim));
                    break;
                }
            }

            if (current_key != NULL) {
                // check which button was pressed
                if( ev->button.button == SDL_BUTTON_LEFT )
                {
                    if(oric->define_mapping) {
                        do_popup( oric, "Press the key you want to use." );
                        defining_key_map = SDL_TRUE;
                    } else {
                        // manage mod keys
                        if (current_key->is_mod_key && oric->sticky_mod_keys) {
                          for (i=0; i<modKeyMax; i++) {
                            if (current_key->keysim == modKeys[i])
                              break;
                          }

                          if (i < modKeyMax) {
                            if (modKeyPressed[i]) {
                              modKeyPressed[i] = SDL_FALSE;
                              snprintf(tmp, sizeof(tmp), "%s released.", modKeyNames[i]);
                            } else {
                              modKeyPressed[i] = SDL_TRUE;
                              snprintf(tmp, sizeof(tmp), "%s pressed.", modKeyNames[i]);
                            }
                            do_popup(oric, tmp);
                            ay_keypress( &oric->ay, current_key->keysim, modKeyPressed[i] );
                            current_key = NULL;
                            return done;
                          }
                        }

                        // send the key to the Oric
                        switch( oric->type )
                        {
                            case MACH_PRAVETZ:
                                if (lshifted) {
                                    if (current_key_num == 24)
                                        queuekeys("\x60");
                                    if (KEYSIM_FLAG & current_key->keysimshifted)
                                        ay_keypress( &oric->ay, modKeys[MOD_LSHIFT], SDL_FALSE );
                                    ay_keypress( &oric->ay, KEYSIM_MASK & current_key->keysimshifted, SDL_TRUE );
                                } else if (rshifted) {
                                    if (current_key_num == 24)
                                        queuekeys("\x60");
                                    if (KEYSIM_FLAG & current_key->keysimshifted)
                                        ay_keypress( &oric->ay, modKeys[MOD_RSHIFT], SDL_FALSE );
                                    ay_keypress( &oric->ay, KEYSIM_MASK & current_key->keysimshifted, SDL_TRUE );
                                } else {
                                    if (current_key_num == 59) {
                                        queuekeys("\x14");
                                    } else if (KEYSIM_FLAG & current_key->keysim) {
                                        ay_keypress( &oric->ay, modKeys[MOD_LSHIFT], SDL_TRUE );
                                        ay_keypress( &oric->ay, KEYSIM_MASK & current_key->keysim, SDL_TRUE );
                                        modKeyFakePressed[MOD_LSHIFT] = SDL_TRUE;
                                    } else {
                                        ay_keypress( &oric->ay, KEYSIM_MASK & current_key->keysim, SDL_TRUE );
                                    }
                                }
                                break;
                            case MACH_ORIC1:
                            case MACH_ORIC1_16K:
                            case MACH_ATMOS:
                            default:
                                ay_keypress( &oric->ay, current_key->keysim, SDL_TRUE );
                                break;
                        }

                        // start releasing mod keys if need be
                        release_keys = SDL_TRUE;
                    }
                }
            }
            break;

        case SDL_MOUSEBUTTONUP:
            if ((current_key == NULL) || (defining_key_map))
                break;

            // send the key to the Oric
            switch( oric->type )
            {
                case MACH_PRAVETZ:
                    if (lshifted || rshifted) {
                        ay_keypress( &oric->ay, KEYSIM_MASK & current_key->keysimshifted, SDL_FALSE );
                    } else {
                        ay_keypress( &oric->ay, KEYSIM_MASK & current_key->keysim, SDL_FALSE );
                    }
                    break;
                case MACH_ORIC1:
                case MACH_ORIC1_16K:
                case MACH_ATMOS:
                default:
                    ay_keypress( &oric->ay, current_key->keysim, SDL_FALSE );
                    break;
            }

            current_key = NULL;
            break;

        case SDL_KEYUP:
            if (defining_key_map) {
                SDL_KeyboardEvent *kbd_evt = (SDL_KeyboardEvent *) ev;
                add_to_keyboard_mapping( &(oric->keyboard_mapping), kbd_evt->keysym.sym, current_key->keysim );
                do_popup( oric, "Key mapping done.");
                defining_key_map = SDL_FALSE;
                current_key = NULL;
            }
            break;

    }
    return done;
}
Beispiel #9
0
static gboolean
swatch_popup_menu (GtkWidget *swatch)
{
  do_popup (swatch, NULL);
  return TRUE;
}