src/gtkimhtml.c

changeset 1515
89a3d8a63734
parent 1482
d7644e9a7e00
child 1519
bbb72e250233
equal deleted inserted replaced
1514:cd2994c09798 1515:89a3d8a63734
243 GdkColormap *cmap; 243 GdkColormap *cmap;
244 GdkWindow *window = GTK_LAYOUT (imhtml)->bin_window; 244 GdkWindow *window = GTK_LAYOUT (imhtml)->bin_window;
245 gfloat xoff, yoff; 245 gfloat xoff, yoff;
246 GdkColor *bg, *fg; 246 GdkColor *bg, *fg;
247 247
248 if (GTK_LAYOUT (imhtml)->freeze_count)
249 return;
250
248 bit = line->bit; 251 bit = line->bit;
249 gc = gdk_gc_new (window); 252 gc = gdk_gc_new (window);
250 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml)); 253 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml));
251 xoff = GTK_LAYOUT (imhtml)->hadjustment->value; 254 xoff = GTK_LAYOUT (imhtml)->hadjustment->value;
252 yoff = GTK_LAYOUT (imhtml)->vadjustment->value; 255 yoff = GTK_LAYOUT (imhtml)->vadjustment->value;
344 gdk_string_width (bit->font, line->text), 1); 347 gdk_string_width (bit->font, line->text), 1);
345 348
346 gdk_gc_unref (gc); 349 gdk_gc_unref (gc);
347 } 350 }
348 351
349 static gint 352 static void
350 draw_img (GtkIMHtml *imhtml, 353 draw_img (GtkIMHtml *imhtml,
351 struct line_info *line) 354 struct line_info *line)
352 { 355 {
353 GtkIMHtmlBit *bit; 356 GtkIMHtmlBit *bit;
354 GdkGC *gc; 357 GdkGC *gc;
355 GdkColormap *cmap; 358 GdkColormap *cmap;
356 gint width, height, hoff; 359 gint width, height, hoff;
357 GdkWindow *window = GTK_LAYOUT (imhtml)->bin_window; 360 GdkWindow *window = GTK_LAYOUT (imhtml)->bin_window;
358 gfloat xoff, yoff; 361 gfloat xoff, yoff;
362
363 if (GTK_LAYOUT (imhtml)->freeze_count)
364 return;
359 365
360 bit = line->bit; 366 bit = line->bit;
361 gdk_window_get_size (bit->pm, &width, &height); 367 gdk_window_get_size (bit->pm, &width, &height);
362 hoff = (line->height - height) / 2; 368 hoff = (line->height - height) / 2;
363 xoff = GTK_LAYOUT (imhtml)->hadjustment->value; 369 xoff = GTK_LAYOUT (imhtml)->hadjustment->value;
383 } 389 }
384 390
385 gdk_draw_pixmap (window, gc, bit->pm, 0, 0, line->x - xoff, line->y - yoff + hoff, -1, -1); 391 gdk_draw_pixmap (window, gc, bit->pm, 0, 0, line->x - xoff, line->y - yoff + hoff, -1, -1);
386 392
387 gdk_gc_unref (gc); 393 gdk_gc_unref (gc);
388 394 }
389 return TRUE; 395
390 } 396 static void
391
392 static gint
393 draw_line (GtkIMHtml *imhtml, 397 draw_line (GtkIMHtml *imhtml,
394 struct line_info *line) 398 struct line_info *line)
395 { 399 {
396 GtkIMHtmlBit *bit; 400 GtkIMHtmlBit *bit;
397 GdkDrawable *drawable; 401 GdkDrawable *drawable;
398 GdkColormap *cmap; 402 GdkColormap *cmap;
399 GdkGC *gc; 403 GdkGC *gc;
400 guint line_height; 404 guint line_height;
401 gfloat xoff, yoff; 405 gfloat xoff, yoff;
402 406
407 if (GTK_LAYOUT (imhtml)->freeze_count)
408 return;
409
403 xoff = GTK_LAYOUT (imhtml)->hadjustment->value; 410 xoff = GTK_LAYOUT (imhtml)->hadjustment->value;
404 yoff = GTK_LAYOUT (imhtml)->vadjustment->value; 411 yoff = GTK_LAYOUT (imhtml)->vadjustment->value;
405 bit = line->bit; 412 bit = line->bit;
406 drawable = GTK_LAYOUT (imhtml)->bin_window; 413 drawable = GTK_LAYOUT (imhtml)->bin_window;
407 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml)); 414 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml));
422 429
423 gdk_draw_rectangle (drawable, gc, TRUE, line->x - xoff, line->y - yoff + line_height / 2, 430 gdk_draw_rectangle (drawable, gc, TRUE, line->x - xoff, line->y - yoff + line_height / 2,
424 line->width, line_height); 431 line->width, line_height);
425 432
426 gdk_gc_unref (gc); 433 gdk_gc_unref (gc);
427
428 return TRUE;
429 } 434 }
430 435
431 static void 436 static void
432 gtk_imhtml_draw_exposed (GtkIMHtml *imhtml) 437 gtk_imhtml_draw_exposed (GtkIMHtml *imhtml)
433 { 438 {
544 gfloat oldvalue; 549 gfloat oldvalue;
545 550
546 vadj = GTK_LAYOUT (imhtml)->vadjustment; 551 vadj = GTK_LAYOUT (imhtml)->vadjustment;
547 oldvalue = vadj->value / vadj->upper; 552 oldvalue = vadj->value / vadj->upper;
548 553
554 gtk_layout_freeze (GTK_LAYOUT (imhtml));
555
556 g_list_free (imhtml->line);
557 imhtml->line = NULL;
558
559 while (imhtml->urls) {
560 g_free (imhtml->urls->data);
561 imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data);
562 }
563
564 imhtml->x = BORDER_SIZE;
565 imhtml->y = BORDER_SIZE + 10;
566 imhtml->llheight = 0;
567 imhtml->llascent = 0;
568
549 b = imhtml->bits; 569 b = imhtml->bits;
550 while (b) { 570 while (b) {
551 bit = b->data; 571 bit = b->data;
552 b = g_list_next (b); 572 b = g_list_next (b);
553 while (bit->chunks) { 573 while (bit->chunks) {
555 if (li->text) 575 if (li->text)
556 g_free (li->text); 576 g_free (li->text);
557 bit->chunks = g_list_remove (bit->chunks, li); 577 bit->chunks = g_list_remove (bit->chunks, li);
558 g_free (li); 578 g_free (li);
559 } 579 }
560 } 580 gtk_imhtml_draw_bit (imhtml, bit);
561 581 }
562 g_list_free (imhtml->line); 582
563 imhtml->line = NULL; 583 if (GTK_LAYOUT (imhtml)->bin_window && (imhtml->y < GTK_WIDGET (imhtml)->allocation.y))
564
565 while (imhtml->urls) {
566 g_free (imhtml->urls->data);
567 imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data);
568 }
569
570 imhtml->x = BORDER_SIZE;
571 imhtml->y = BORDER_SIZE + 10;
572 imhtml->llheight = 0;
573 imhtml->llascent = 0;
574
575 if (GTK_LAYOUT (imhtml)->bin_window)
576 gdk_window_clear (GTK_LAYOUT (imhtml)->bin_window); 584 gdk_window_clear (GTK_LAYOUT (imhtml)->bin_window);
577
578 b = imhtml->bits;
579 while (b) {
580 gtk_imhtml_draw_bit (imhtml, b->data);
581 b = g_list_next (b);
582 }
583 585
584 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y + 5); 586 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y + 5);
585 gtk_adjustment_set_value (vadj, vadj->upper * oldvalue); 587 gtk_adjustment_set_value (vadj, vadj->upper * oldvalue);
588
589 gtk_layout_thaw (GTK_LAYOUT (imhtml));
586 } 590 }
587 591
588 static void 592 static void
589 gtk_imhtml_size_allocate (GtkWidget *widget, 593 gtk_imhtml_size_allocate (GtkWidget *widget,
590 GtkAllocation *allocation) 594 GtkAllocation *allocation)
654 chunks = g_list_next (chunks); 658 chunks = g_list_next (chunks);
655 } 659 }
656 660
657 bits = g_list_next (bits); 661 bits = g_list_next (bits);
658 } 662 }
663 imhtml->sel_endchunk = NULL;
659 } 664 }
660 665
661 static gchar* 666 static gchar*
662 get_position (struct line_info *chunk, 667 get_position (struct line_info *chunk,
663 gint x, 668 gint x,
813 chunk->sel_end = chunk->sel_start; 818 chunk->sel_end = chunk->sel_start;
814 chunk->sel_start = new_pos; 819 chunk->sel_start = new_pos;
815 } else 820 } else
816 chunk->sel_end = new_pos; 821 chunk->sel_end = new_pos;
817 selection = 2; 822 selection = 2;
823 imhtml->sel_endchunk = chunk;
818 got_end = TRUE; 824 got_end = TRUE;
819 } else { 825 } else {
820 new_pos = get_position (chunk, endx, smileys); 826 new_pos = get_position (chunk, endx, smileys);
821 if ( !chunk->selected || 827 if ( !chunk->selected ||
822 (chunk->sel_start != new_pos) || 828 (chunk->sel_start != new_pos) ||
824 redraw = TRUE; 830 redraw = TRUE;
825 chunk->selected = TRUE; 831 chunk->selected = TRUE;
826 chunk->sel_start = new_pos; 832 chunk->sel_start = new_pos;
827 chunk->sel_end = NULL; 833 chunk->sel_end = NULL;
828 selection++; 834 selection++;
835 imhtml->sel_endchunk = chunk;
829 got_end = TRUE; 836 got_end = TRUE;
830 } 837 }
831 } else if (!COORDS_IN_CHUNK (startx, starty) && !got_start) { 838 } else if (!COORDS_IN_CHUNK (startx, starty) && !got_start) {
832 if (chunk->selected) 839 if (chunk->selected)
833 redraw = TRUE; 840 redraw = TRUE;
857 redraw = TRUE; 864 redraw = TRUE;
858 chunk->selected = TRUE; 865 chunk->selected = TRUE;
859 chunk->sel_start = chunk->text; 866 chunk->sel_start = chunk->text;
860 chunk->sel_end = new_pos; 867 chunk->sel_end = new_pos;
861 selection++; 868 selection++;
869 imhtml->sel_endchunk = chunk;
862 got_end = TRUE; 870 got_end = TRUE;
863 } else { 871 } else {
864 if ( !chunk->selected || 872 if ( !chunk->selected ||
865 (chunk->sel_end != NULL) || 873 (chunk->sel_end != NULL) ||
866 (chunk->sel_start != chunk->text)) 874 (chunk->sel_start != chunk->text))
899 907
900 bits = g_list_next (bits); 908 bits = g_list_next (bits);
901 } 909 }
902 } 910 }
903 911
912 static void
913 gtk_imhtml_select_in_chunk (GtkIMHtml *imhtml,
914 struct line_info *chunk)
915 {
916 GtkIMHtmlBit *bit = chunk->bit;
917 gchar *new_pos;
918 guint endx = imhtml->sel_endx;
919 guint startx = imhtml->sel_startx;
920 guint starty = imhtml->sel_starty;
921 gboolean smileys = imhtml->smileys;
922 gboolean redraw = FALSE;
923
924 new_pos = get_position (chunk, endx, smileys);
925 if ((starty < chunk->y) ||
926 ((starty < chunk->y + chunk->height) && (startx < endx))) {
927 if (chunk->sel_end != new_pos)
928 redraw = TRUE;
929 chunk->sel_end = new_pos;
930 } else {
931 if (chunk->sel_start != new_pos)
932 redraw = TRUE;
933 chunk->sel_start = new_pos;
934 }
935
936 if (redraw) {
937 if (DRAW_IMG (bit))
938 draw_img (imhtml, chunk);
939 else if ((bit->type == TYPE_SEP) &&
940 (bit->chunks->data == chunk))
941 draw_line (imhtml, chunk);
942 else
943 draw_text (imhtml, chunk);
944 }
945 }
946
904 static gint 947 static gint
905 scroll_timeout (GtkIMHtml *imhtml) 948 scroll_timeout (GtkIMHtml *imhtml)
906 { 949 {
907 GdkEventMotion event; 950 GdkEventMotion event;
908 gint x, y; 951 gint x, y;
957 gtk_adjustment_set_value (vadj, 1000 gtk_adjustment_set_value (vadj,
958 MIN (vadj->value + diff, vadj->upper - height + 20)); 1001 MIN (vadj->value + diff, vadj->upper - height + 20));
959 } 1002 }
960 1003
961 if (imhtml->selection) { 1004 if (imhtml->selection) {
1005 struct line_info *chunk = imhtml->sel_endchunk;
962 imhtml->sel_endx = MAX (x, 0); 1006 imhtml->sel_endx = MAX (x, 0);
963 imhtml->sel_endy = MAX (y, 0); 1007 imhtml->sel_endy = MAX (y, 0);
964 gtk_imhtml_select_bits (imhtml); 1008 if ((chunk == NULL) ||
1009 (x < chunk->x) ||
1010 (x > chunk->x + chunk->width) ||
1011 (y < chunk->y) ||
1012 (y > chunk->y + chunk->height))
1013 gtk_imhtml_select_bits (imhtml);
1014 else
1015 gtk_imhtml_select_in_chunk (imhtml, chunk);
965 } 1016 }
966 } else { 1017 } else {
967 GList *urls = imhtml->urls; 1018 GList *urls = imhtml->urls;
968 struct url_widget *uw; 1019 struct url_widget *uw;
969 1020

mercurial