~ubuntu-branches/debian/experimental/geany/experimental

« back to all changes in this revision

Viewing changes to scintilla/PlatGTK.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2008-05-02 11:37:45 UTC
  • mfrom: (1.2.1 upstream) (3.1.6 hardy)
  • Revision ID: james.westby@ubuntu.com-20080502113745-xzp4g6dmovrpoj17
Tags: 0.14-1
New upstream release (Closes: #478126)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
   with gdk_string_extents. */
32
32
#define FAST_WAY
33
33
 
34
 
#ifdef G_OS_WIN32
35
 
#define snprintf _snprintf
36
 
#endif
37
 
 
38
34
#if GTK_MAJOR_VERSION >= 2
39
35
#define USE_PANGO 1
40
36
#include "Converter.h"
572
568
                                                faceName, sizeof(faceName),
573
569
                                                charset, sizeof(charset));
574
570
 
575
 
                        snprintf(fontspec,
 
571
                        g_snprintf(fontspec,
576
572
                                 sizeof(fontspec) - 1,
577
573
                                 spec,
578
574
                                 foundary, faceName,
588
584
                                strncat(fontset, fontspec, remaining - 1);
589
585
                                remaining -= strlen(fontset);
590
586
 
591
 
                                snprintf(fontspec,
 
587
                                g_snprintf(fontspec,
592
588
                                         sizeof(fontspec) - 1,
593
589
                                         ",%s%s%s-o-*-*-*-%0d-*-*-*-*-%s",
594
590
                                         foundary, faceName,
623
619
                                faceName, sizeof(faceName),
624
620
                                charset, sizeof(charset));
625
621
 
626
 
        snprintf(fontspec,
 
622
        g_snprintf(fontspec,
627
623
                 sizeof(fontspec) - 1,
628
624
                 "%s%s%s%s-*-*-*-%0d-*-*-*-*-%s",
629
625
                 foundary, faceName,
634
630
        newid = LoadFontOrSet(fontspec, characterSet);
635
631
        if (!newid) {
636
632
                // some fonts have oblique, not italic
637
 
                snprintf(fontspec,
 
633
                g_snprintf(fontspec,
638
634
                         sizeof(fontspec) - 1,
639
635
                         "%s%s%s%s-*-*-*-%0d-*-*-*-*-%s",
640
636
                         foundary, faceName,
645
641
                newid = LoadFontOrSet(fontspec, characterSet);
646
642
        }
647
643
        if (!newid) {
648
 
                snprintf(fontspec,
 
644
                g_snprintf(fontspec,
649
645
                         sizeof(fontspec) - 1,
650
646
                         "-*-*-*-*-*-*-*-%0d-*-*-*-*-%s",
651
647
                         size * 10,
745
741
        case SC_CHARSET_ANSI:
746
742
                return "";
747
743
        case SC_CHARSET_DEFAULT:
748
 
                return "LATIN1";
 
744
                return "ISO-8859-1";
749
745
        case SC_CHARSET_BALTIC:
750
746
                return "ISO-8859-13";
751
747
        case SC_CHARSET_CHINESEBIG5:
1053
1049
#else
1054
1050
void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill,
1055
1051
                ColourAllocated outline, int alphaOutline, int flags) {
1056
 
        if (gc && drawable) {
 
1052
        if (gc && drawable && rc.Width() > 0) {
1057
1053
                int width = rc.Width();
1058
1054
                int height = rc.Height();
1059
1055
                // Ensure not distorted too much by corners when small
1293
1289
                                len = maxLengthTextRun-1;
1294
1290
                        int wclen;
1295
1291
                        if (et == UTF8) {
1296
 
                                wclen = UCS2FromUTF8(s, len,
 
1292
                                wclen = UTF16FromUTF8(s, len,
1297
1293
                                        static_cast<wchar_t *>(static_cast<void *>(wctext)), maxLengthTextRun - 1);
1298
1294
                        } else {        // dbcs, so convert using current locale
1299
1295
                                char sMeasure[maxLengthTextRun];
1383
1379
                                        pango_layout_iter_get_cluster_extents(iter, NULL, &pos);
1384
1380
                                        int position = PANGO_PIXELS(pos.x);
1385
1381
                                        int curIndex = pango_layout_iter_get_index(iter);
 
1382
                                        int places = curIndex - i;
 
1383
                                        int distance = position - positions[i-1];
1386
1384
                                        while (i < curIndex) {
1387
 
                                                positions[i++] = position;
 
1385
                                                // Evenly distribute space among bytes of this cluster.
 
1386
                                                // Would be better to find number of characters and then
 
1387
                                                // divide evenly between characters with each byte of a character
 
1388
                                                // being at the same position.
 
1389
                                                positions[i] = position - (curIndex - 1 - i) * distance / places;
 
1390
                                                i++;
1388
1391
                                        }
1389
1392
                                }
1390
1393
                                while (i < lenPositions)
1436
1439
                                                utfForm = UTF8FromLatin1(s, len);
1437
1440
                                        }
1438
1441
                                        pango_layout_set_text(layout, utfForm, len);
 
1442
                                        PangoLayoutIter *iter = pango_layout_get_iter(layout);
 
1443
                                        pango_layout_iter_get_cluster_extents(iter, NULL, &pos);
1439
1444
                                        int i = 0;
1440
 
                                        PangoLayoutIter *iter = pango_layout_get_iter(layout);
1441
 
                                        pango_layout_iter_get_cluster_extents(iter, NULL, &pos);
 
1445
                                        int positionStart = 0;
 
1446
                                        int clusterStart = 0;
 
1447
                                        // Each Latin1 input character may take 1 or 2 bytes in UTF-8
 
1448
                                        // and groups of up to 3 may be represented as ligatures.
1442
1449
                                        while (pango_layout_iter_next_cluster(iter)) {
1443
1450
                                                pango_layout_iter_get_cluster_extents(iter, NULL, &pos);
1444
 
                                                positions[i++] = PANGO_PIXELS(pos.x);
 
1451
                                                int position = PANGO_PIXELS(pos.x);
 
1452
                                                int distance = position - positionStart;
 
1453
                                                int clusterEnd = pango_layout_iter_get_index(iter);
 
1454
                                                int ligatureLength = g_utf8_strlen(utfForm + clusterStart, clusterEnd - clusterStart);
 
1455
                                                PLATFORM_ASSERT(ligatureLength > 0 && ligatureLength <= 3);
 
1456
                                                for (int charInLig=0; charInLig<ligatureLength; charInLig++) {
 
1457
                                                        positions[i++] = position - (ligatureLength - 1 - charInLig) * distance / ligatureLength;
 
1458
                                                }
 
1459
                                                positionStart = position;
 
1460
                                                clusterStart = clusterEnd;
1445
1461
                                        }
1446
1462
                                        while (i < lenPositions)
1447
1463
                                                positions[i++] = PANGO_PIXELS(pos.x + pos.width);
1468
1484
                                len = maxLengthTextRun-1;
1469
1485
                        int wclen;
1470
1486
                        if (et == UTF8) {
1471
 
                                wclen = UCS2FromUTF8(s, len,
 
1487
                                wclen = UTF16FromUTF8(s, len,
1472
1488
                                        static_cast<wchar_t *>(static_cast<void *>(wctext)), maxLengthTextRun - 1);
1473
1489
                        } else {        // dbcsMode, so convert using current locale
1474
1490
                                char sDraw[maxLengthTextRun];
1554
1570
#endif
1555
1571
                if (et == UTF8) {
1556
1572
                        GdkWChar wctext[maxLengthTextRun];
1557
 
                        size_t wclen = UCS2FromUTF8(s, len, static_cast<wchar_t *>(static_cast<void *>(wctext)),
 
1573
                        size_t wclen = UTF16FromUTF8(s, len, static_cast<wchar_t *>(static_cast<void *>(wctext)),
1558
1574
                                sizeof(wctext) / sizeof(GdkWChar) - 1);
1559
1575
                        wctext[wclen] = L'\0';
1560
1576
                        return gdk_text_width_wc(PFont(font_)->pfont, wctext, wclen);
1854
1870
        gtk_window_set_title(GTK_WINDOW(id), s);
1855
1871
}
1856
1872
 
 
1873
/* Returns rectangle of monitor pt is on, both rect and pt are in Window's
 
1874
   gdk window coordinates */
 
1875
PRectangle Window::GetMonitorRect(Point pt) {
 
1876
        gint x_offset, y_offset;
 
1877
        pt = pt;
 
1878
 
 
1879
        gdk_window_get_origin(PWidget(id)->window, &x_offset, &y_offset);
 
1880
 
 
1881
// gtk 2.2+
 
1882
#if GTK_MAJOR_VERSION > 2 || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 2)
 
1883
        {
 
1884
                GdkScreen* screen;
 
1885
                gint monitor_num;
 
1886
                GdkRectangle rect;
 
1887
 
 
1888
                screen = gtk_widget_get_screen(PWidget(id));
 
1889
                monitor_num = gdk_screen_get_monitor_at_point(screen, pt.x + x_offset, pt.y + y_offset);
 
1890
                gdk_screen_get_monitor_geometry(screen, monitor_num, &rect);
 
1891
                rect.x -= x_offset;
 
1892
                rect.y -= y_offset;
 
1893
                return PRectangle(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
 
1894
        }
 
1895
#else
 
1896
        return PRectangle(-x_offset, -y_offset, (-x_offset) + gdk_screen_width(),
 
1897
                          (-y_offset) + gdk_screen_height());
 
1898
#endif
 
1899
}
 
1900
 
1857
1901
struct ListImage {
1858
1902
        const char *xpm_data;
1859
1903
#if GTK_MAJOR_VERSION < 2
2283
2327
                return;
2284
2328
        }
2285
2329
 
2286
 
        bool valid = gtk_tree_model_iter_nth_child(model, &iter, NULL, n);
 
2330
        bool valid = gtk_tree_model_iter_nth_child(model, &iter, NULL, n) != FALSE;
2287
2331
        if (valid) {
2288
2332
                gtk_tree_selection_select_iter(selection, &iter);
2289
2333
 
2356
2400
        GtkTreeIter iter;
2357
2401
        GtkTreeModel *model =
2358
2402
                gtk_tree_view_get_model(GTK_TREE_VIEW(list));
2359
 
        bool valid = gtk_tree_model_get_iter_first(model, &iter);
 
2403
        bool valid = gtk_tree_model_get_iter_first(model, &iter) != FALSE;
2360
2404
        int i = 0;
2361
2405
        while(valid) {
2362
2406
                gchar *s;
2364
2408
                if (s && (0 == strncmp(prefix, s, strlen(prefix)))) {
2365
2409
                        return i;
2366
2410
                }
2367
 
                valid = gtk_tree_model_iter_next(model, &iter);
 
2411
                valid = gtk_tree_model_iter_next(model, &iter) != FALSE;
2368
2412
                i++;
2369
2413
        }
2370
2414
#endif
2388
2432
#else
2389
2433
        GtkTreeIter iter;
2390
2434
        GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list));
2391
 
        bool valid = gtk_tree_model_iter_nth_child(model, &iter, NULL, n);
 
2435
        bool valid = gtk_tree_model_iter_nth_child(model, &iter, NULL, n) != FALSE;
2392
2436
        if (valid) {
2393
2437
                gtk_tree_model_get(model, &iter, TEXT_COLUMN, &text, -1);
2394
2438
        }
2609
2653
}
2610
2654
 
2611
2655
void Platform::DebugDisplay(const char *s) {
2612
 
        printf("%s", s);
 
2656
        fprintf(stderr, "%s", s);
2613
2657
}
2614
2658
 
2615
2659
bool Platform::IsKeyDown(int) {