~ubuntu-branches/ubuntu/maverick/crossfire-client/maverick

« back to all changes in this revision

Viewing changes to gtk-v2/src/keys.c

  • Committer: Bazaar Package Importer
  • Author(s): Kari Pahula
  • Date: 2007-04-13 21:15:44 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070413211544-vjo6zesj6g0wgmwf
Tags: 1.10.0-1
* New upstream release
* Install the README, README-dev and TODO files specific to the GTK2
  client to the corresponding package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
char *rcsid_gtk2_keys_c =
2
 
    "$Id: keys.c,v 1.7 2006/03/04 15:56:33 akirschbaum Exp $";
 
2
    "$Id: keys.c 5010 2006-10-07 18:29:47Z qal21 $";
3
3
/*
4
4
    Crossfire client, a client program for the crossfire program.
5
5
 
68
68
static GtkListStore    *keybinding_store;
69
69
static GtkTreeSelection  *keybinding_selection;
70
70
 
 
71
/* Changed to KLIST_* to avoid conflicts in Win2000 and up */
71
72
enum {
72
 
    LIST_ENTRY, LIST_KEY, LIST_MODS, LIST_EDIT, LIST_COMMAND, LIST_KEY_ENTRY
 
73
    KLIST_ENTRY, KLIST_KEY, KLIST_MODS, KLIST_EDIT, KLIST_COMMAND, KLIST_KEY_ENTRY
73
74
};
74
75
 
75
76
GtkWidget *spinbutton_count;
320
321
 
321
322
        /* Rest of the line is the actual command.  Lets kill the newline */
322
323
        cpnext[strlen(cpnext)-1]='\0';
323
 
    if (strlen(cpnext)>(sizeof(bind_buf)-1)){
324
 
        cpnext[sizeof(bind_buf)-1]='\0';
325
 
        LOG(LOG_WARNING,"gtk::parse_keybind_line","Had to truncate a too long command");
326
 
    }
 
324
        if (strlen(cpnext)>(sizeof(bind_buf)-1)){
 
325
            cpnext[sizeof(bind_buf)-1]='\0';
 
326
            LOG(LOG_WARNING,"gtk::parse_keybind_line","Had to truncate a too long command");
 
327
        }
 
328
 
327
329
        insert_key(keysym, flags | standard, cpnext);
328
330
    } /* else if not special binding line */
329
331
}
436
438
 
437
439
    renderer = gtk_cell_renderer_text_new ();
438
440
    column = gtk_tree_view_column_new_with_attributes ("Key", renderer,
439
 
                                                      "text", LIST_KEY,
 
441
                                                      "text", KLIST_KEY,
440
442
                                                      NULL);
441
 
    gtk_tree_view_column_set_sort_column_id(column, LIST_KEY);
 
443
    gtk_tree_view_column_set_sort_column_id(column, KLIST_KEY);
442
444
    gtk_tree_view_append_column (GTK_TREE_VIEW (keybinding_treeview), column);
443
445
 
444
446
    renderer = gtk_cell_renderer_text_new ();
445
447
    column = gtk_tree_view_column_new_with_attributes ("Modifiers", renderer,
446
 
                                                      "text", LIST_MODS,
 
448
                                                      "text", KLIST_MODS,
447
449
                                                      NULL);
448
 
    gtk_tree_view_column_set_sort_column_id(column, LIST_MODS);
 
450
    gtk_tree_view_column_set_sort_column_id(column, KLIST_MODS);
449
451
    gtk_tree_view_append_column (GTK_TREE_VIEW (keybinding_treeview), column);
450
452
 
451
453
    renderer = gtk_cell_renderer_text_new ();
452
454
    column = gtk_tree_view_column_new_with_attributes ("Edit Mode", renderer,
453
 
                                                      "text", LIST_EDIT,
 
455
                                                      "text", KLIST_EDIT,
454
456
                                                      NULL);
455
 
    gtk_tree_view_column_set_sort_column_id(column, LIST_EDIT);
 
457
    gtk_tree_view_column_set_sort_column_id(column, KLIST_EDIT);
456
458
    gtk_tree_view_append_column (GTK_TREE_VIEW (keybinding_treeview), column);
457
459
 
458
460
    renderer = gtk_cell_renderer_text_new ();
459
461
    column = gtk_tree_view_column_new_with_attributes ("Command", renderer,
460
 
                                                      "text", LIST_COMMAND,
 
462
                                                      "text", KLIST_COMMAND,
461
463
                                                      NULL);
462
 
    gtk_tree_view_column_set_sort_column_id(column, LIST_COMMAND);
 
464
    gtk_tree_view_column_set_sort_column_id(column, KLIST_COMMAND);
463
465
    gtk_tree_view_append_column (GTK_TREE_VIEW (keybinding_treeview), column);
464
466
 
465
467
 
468
470
    gtk_tree_selection_set_select_function(keybinding_selection, keybinding_selection_func, NULL, NULL);
469
471
 
470
472
    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(keybinding_store),
471
 
                                             LIST_KEY,
 
473
                                             KLIST_KEY,
472
474
                                             GTK_SORT_ASCENDING);
473
475
 
474
476
 
546
548
{
547
549
    Key_Entry *keyentry, *first_match=NULL;
548
550
    int present_flags=0;
549
 
    char buf[MAX_BUF];
 
551
    char buf[MAX_BUF], tmpbuf[MAX_BUF];
550
552
 
551
553
    if (keysym==commandkeysym) {
552
554
        gtk_widget_grab_focus (GTK_WIDGET(entry_commands));
635
637
        gtk_spin_button_set_value (GTK_SPIN_BUTTON(spinbutton_count), (float) cpl.count );
636
638
        return;
637
639
    }
638
 
    sprintf(buf, "Key unused (%s%s%s)",
639
 
          (cpl.fire_on? "Fire&": ""),
640
 
          (cpl.run_on ? "Run&" : ""),
641
 
          keysym==NoSymbol? "unknown": gdk_keyval_name(keysym));
 
640
    tmpbuf[0]=0;
 
641
    if (cpl.fire_on) strcat(tmpbuf,"fire+");
 
642
    if (cpl.run_on) strcat(tmpbuf,"run+");
 
643
    if (cpl.alt_on) strcat(tmpbuf,"alt+");
 
644
    if (cpl.meta_on) strcat(tmpbuf,"meta+");
 
645
 
 
646
    sprintf(buf, "Key %s%s is not bound to any command.  Use bind to associate this keypress with a command",
 
647
            tmpbuf, keysym==NoSymbol? "unknown": gdk_keyval_name(keysym));
642
648
#ifdef WIN32
643
649
       if ( ( 65513 != keysym ) && ( 65511 != keysym ) )
644
650
#endif
907
913
 
908
914
    if (strlen(params) >= sizeof(bind_buf)) {
909
915
        params[sizeof(bind_buf) - 1] = '\0';
910
 
    draw_info("Keybinding too long! Truncated:",NDI_RED);
911
 
    draw_info(params,NDI_RED);
 
916
        draw_info("Keybinding too long! Truncated:",NDI_RED);
 
917
        draw_info(params,NDI_RED);
912
918
    }
913
919
    sprintf(buf, "Push key to bind '%s'.", params);
914
920
    draw_info(buf,NDI_BLACK);
1019
1025
static void configure_keys(uint32 keysym)
1020
1026
{
1021
1027
    char buf[MAX_BUF];
 
1028
    Key_Entry *keyentry, *first_match=NULL;
1022
1029
 
1023
1030
    /* I think that basically if we are not rebinding the special
1024
1031
     * control keys (in which case bind_kesym would be set to something)
1064
1071
        bind_keysym=NULL;
1065
1072
    }
1066
1073
    else {
 
1074
        keyentry = keys[keysym % KEYHASH];
 
1075
        while (keyentry!=NULL) {
 
1076
            if ((keyentry->keysym!=0 && keyentry->keysym!=keysym) ||
 
1077
                (!(keyentry->flags & bind_flags))) {
 
1078
                    keyentry=keyentry->next;
 
1079
                    continue;
 
1080
            }
 
1081
            first_match = keyentry;
 
1082
 
 
1083
            /* Try to find a prefect match */
 
1084
            if ((keyentry->flags & KEYF_MODIFIERS)!= bind_flags) {
 
1085
                keyentry=keyentry->next;
 
1086
                continue;
 
1087
            }
 
1088
            else break;
 
1089
        }
 
1090
        if (first_match) {
 
1091
            sprintf(buf, "Warning: Keybind %s may conflict with new binding.", first_match->command);
 
1092
            draw_info(buf,NDI_RED);
 
1093
        }
 
1094
 
1067
1095
        insert_key(keysym, bind_flags, bind_buf);
1068
1096
    }
1069
1097
 
1158
1186
    sprintf(buf,"Removed binding: %3d %s", count, get_key_info(key,0));
1159
1187
 
1160
1188
    draw_info(buf,NDI_BLACK);
1161
 
    if (key->command) free(key->command);
 
1189
    free(key->command);
1162
1190
    free(key);
1163
1191
    save_keys();
1164
1192
}
1401
1429
                                        gpointer         user_data)
1402
1430
{
1403
1431
    const gchar *entry_text;
1404
 
    extern GtkWidget *textview_info1;
 
1432
    extern GtkWidget *treeview_look;
1405
1433
 
1406
1434
    /* Next reply will reset this as necessary */
1407
1435
    if (!use_config[CONFIG_POPUPS])
1439
1467
     * it doesn't make much difference what widget this is set
1440
1468
     * to, as long as it is something that can get focus.
1441
1469
     */
1442
 
    gtk_widget_grab_focus (GTK_WIDGET(textview_info1));
 
1470
    gtk_widget_grab_focus (GTK_WIDGET(treeview_look));
1443
1471
 
1444
1472
    if( cpl.input_state == Metaserver_Select)
1445
1473
    {
1481
1509
            if (key->flags & KEYF_STANDARD)  strcat(modifier_buf,"(Standard) ");
1482
1510
            gtk_list_store_append(keybinding_store, &iter);
1483
1511
            gtk_list_store_set(keybinding_store, &iter,
1484
 
                               LIST_ENTRY, i,
1485
 
                               LIST_KEY,  gdk_keyval_name(key->keysym),
1486
 
                               LIST_MODS, modifier_buf,
1487
 
                               LIST_EDIT, (key->flags & KEYF_EDIT) ? "Yes":"No",
1488
 
                               LIST_COMMAND, key->command,
1489
 
                               LIST_KEY_ENTRY, key,
 
1512
                               KLIST_ENTRY, i,
 
1513
                               KLIST_KEY,  gdk_keyval_name(key->keysym),
 
1514
                               KLIST_MODS, modifier_buf,
 
1515
                               KLIST_EDIT, (key->flags & KEYF_EDIT) ? "Yes":"No",
 
1516
                               KLIST_COMMAND, key->command,
 
1517
                               KLIST_KEY_ENTRY, key,
1490
1518
                               -1);
1491
1519
        }
1492
1520
    }
1562
1590
        LOG(LOG_ERROR,"keys.c:on_keybinding_button_remove_clicked", "Function called with nothing selected\n");
1563
1591
        return;
1564
1592
    }
1565
 
    gtk_tree_model_get(model, &iter, LIST_KEY_ENTRY, &entry, -1);
 
1593
    gtk_tree_model_get(model, &iter, KLIST_KEY_ENTRY, &entry, -1);
1566
1594
    for (onkey=0; onkey<KEYHASH; onkey++) {
1567
1595
        for (key=keys[onkey]; key; key =key->next) {
1568
1596
            if (key == entry) {
1589
1617
    LOG(LOG_ERROR,"keys.c:on_keybinding_button_remove_clicked", "Unable to find matching key entry\n");
1590
1618
 
1591
1619
unbinded:
1592
 
    if (key->command) free(key->command);
 
1620
    free(key->command);
1593
1621
    free(key);
1594
1622
    save_keys();
1595
1623
    update_keybinding_list();
1681
1709
    const char *buf;
1682
1710
 
1683
1711
    if (gtk_tree_selection_get_selected (keybinding_selection, &model, &iter)) {
1684
 
        gtk_tree_model_get(model, &iter, LIST_KEY_ENTRY, &entry, -1);
 
1712
        gtk_tree_model_get(model, &iter, KLIST_KEY_ENTRY, &entry, -1);
1685
1713
 
1686
1714
        if (!entry) {
1687
1715
            LOG(LOG_ERROR,"keys.c:on_keybinding_button_update_clicked", "Unable to get key_entry structure\n");
1688
1716
            return;
1689
1717
        }
1690
 
        if (entry->command) free(entry->command);
 
1718
        free(entry->command);
1691
1719
        keybinding_get_data(&entry->keysym, &entry->flags, &buf);
1692
1720
        entry->command = strdup_local(buf);
1693
1721
        update_keybinding_list();
1727
1755
 
1728
1756
    if (gtk_tree_model_get_iter(model, &iter, path)) {
1729
1757
 
1730
 
        gtk_tree_model_get(model, &iter, LIST_KEY_ENTRY, &entry, -1);
 
1758
        gtk_tree_model_get(model, &iter, KLIST_KEY_ENTRY, &entry, -1);
1731
1759
 
1732
1760
        if (!entry) {
1733
1761
            LOG(LOG_ERROR,"keys.c:keybinding_selection_func", "Unable to get key_entry structure\n");