Mercurial > audlegacy
comparison src/audacious/ui_skinned_textbox.c @ 2945:09c216d437b2 trunk
Backed out changeset 3c66c8d03c534692d1606ed3ed79634e227f7bd2
As implemented, this diff breaks the UI.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 01 Jul 2007 04:48:08 -0500 |
parents | 3c66c8d03c53 |
children | 13591e28d89e |
comparison
equal
deleted
inserted
replaced
2944:3c66c8d03c53 | 2945:09c216d437b2 |
---|---|
46 }; | 46 }; |
47 | 47 |
48 struct _UiSkinnedTextboxPrivate { | 48 struct _UiSkinnedTextboxPrivate { |
49 GtkWidget *image; | 49 GtkWidget *image; |
50 GdkGC *gc; | 50 GdkGC *gc; |
51 gint w; | |
51 SkinPixmapId skin_index; | 52 SkinPixmapId skin_index; |
52 GtkWidget *fixed; | 53 GtkWidget *fixed; |
53 gboolean double_size; | 54 gboolean double_size; |
54 gboolean scroll_back; | 55 gboolean scroll_back; |
55 gint nominal_y, nominal_height; | 56 gint nominal_y, nominal_height; |
266 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | 267 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); |
267 textbox->height = bmp_active_skin->properties.textbox_bitmap_font_height; | 268 textbox->height = bmp_active_skin->properties.textbox_bitmap_font_height; |
268 textbox->x = x; | 269 textbox->x = x; |
269 textbox->y = y; | 270 textbox->y = y; |
270 priv->gc = gc; | 271 priv->gc = gc; |
271 textbox->weight = w; | 272 priv->w = w; |
272 priv->scroll_allowed = allow_scroll; | 273 priv->scroll_allowed = allow_scroll; |
273 priv->scroll_enabled = TRUE; | 274 priv->scroll_enabled = TRUE; |
274 priv->skin_index = si; | 275 priv->skin_index = si; |
275 priv->nominal_y = y; | 276 priv->nominal_y = y; |
276 priv->nominal_height = textbox->height; | 277 priv->nominal_height = textbox->height; |
277 priv->scroll_timeout = 0; | 278 priv->scroll_timeout = 0; |
278 | 279 |
279 priv->fixed = fixed; | 280 priv->fixed = fixed; |
280 priv->double_size = FALSE; | 281 priv->double_size = FALSE; |
281 | 282 |
282 gtk_widget_set_size_request(widget, textbox->weight, textbox->height); | 283 gtk_widget_set_size_request(widget, priv->w, textbox->height); |
283 gtk_fixed_put(GTK_FIXED(priv->fixed), widget, textbox->x, textbox->y); | 284 gtk_fixed_put(GTK_FIXED(priv->fixed), widget, textbox->x, textbox->y); |
284 } | 285 } |
285 | 286 |
286 static void ui_skinned_textbox_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | 287 static void ui_skinned_textbox_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { |
287 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | 288 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); |
303 widget->allocation.width, widget->allocation.height); | 304 widget->allocation.width, widget->allocation.height); |
304 | 305 |
305 textbox->x = widget->allocation.x/(priv->double_size ? 2 : 1); | 306 textbox->x = widget->allocation.x/(priv->double_size ? 2 : 1); |
306 textbox->y = widget->allocation.y/(priv->double_size ? 2 : 1); | 307 textbox->y = widget->allocation.y/(priv->double_size ? 2 : 1); |
307 | 308 |
308 if (textbox->weight != widget->allocation.width) { | 309 if (priv->w != widget->allocation.width) { |
309 textbox->weight = widget->allocation.width; | 310 priv->w = widget->allocation.width; |
310 if (priv->pixmap_text) g_free(priv->pixmap_text); | 311 if (priv->pixmap_text) g_free(priv->pixmap_text); |
311 priv->pixmap_text = NULL; | 312 priv->pixmap_text = NULL; |
312 priv->offset = 0; | 313 priv->offset = 0; |
313 textbox->redraw = TRUE; | 314 ui_skinned_textbox_redraw(textbox); |
314 } | 315 } |
315 } | 316 } |
316 | 317 |
317 static gboolean ui_skinned_textbox_textbox_press(GtkWidget *widget, GdkEventButton *event) { | 318 static gboolean ui_skinned_textbox_textbox_press(GtkWidget *widget, GdkEventButton *event) { |
318 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | 319 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); |
321 if (event->type == GDK_BUTTON_PRESS) { | 322 if (event->type == GDK_BUTTON_PRESS) { |
322 textbox = UI_SKINNED_TEXTBOX(widget); | 323 textbox = UI_SKINNED_TEXTBOX(widget); |
323 | 324 |
324 if (event->button == 1) { | 325 if (event->button == 1) { |
325 if (priv->scroll_allowed) { | 326 if (priv->scroll_allowed) { |
326 if ((priv->pixmap_width > textbox->weight) && priv->is_scrollable) { | 327 if ((priv->pixmap_width > priv->w) && priv->is_scrollable) { |
327 priv->is_dragging = TRUE; | 328 priv->is_dragging = TRUE; |
328 textbox->redraw = TRUE; | 329 textbox->redraw = TRUE; |
329 priv->drag_off = priv->offset; | 330 priv->drag_off = priv->offset; |
330 priv->drag_x = event->x; | 331 priv->drag_x = event->x; |
331 } | 332 } |
358 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | 359 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); |
359 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | 360 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); |
360 | 361 |
361 if (priv->is_dragging) { | 362 if (priv->is_dragging) { |
362 if (priv->scroll_allowed && | 363 if (priv->scroll_allowed && |
363 priv->pixmap_width > textbox->weight) { | 364 priv->pixmap_width > priv->w) { |
364 priv->offset = priv->drag_off - (event->x - priv->drag_x); | 365 priv->offset = priv->drag_off - (event->x - priv->drag_x); |
365 | 366 |
366 while (priv->offset < 0) | 367 while (priv->offset < 0) |
367 priv->offset = 0; | 368 priv->offset = 0; |
368 | 369 |
369 while (priv->offset > (priv->pixmap_width - textbox->weight)) | 370 while (priv->offset > (priv->pixmap_width - priv->w)) |
370 priv->offset = (priv->pixmap_width - textbox->weight); | 371 priv->offset = (priv->pixmap_width - priv->w); |
371 | 372 |
372 textbox->redraw = TRUE; | 373 ui_skinned_textbox_redraw(textbox); |
373 ui_skinned_textbox_paint(textbox); | |
374 } | 374 } |
375 } | 375 } |
376 | 376 |
377 return FALSE; | 377 return FALSE; |
378 } | 378 } |
384 static void ui_skinned_textbox_toggle_doublesize(UiSkinnedTextbox *textbox) { | 384 static void ui_skinned_textbox_toggle_doublesize(UiSkinnedTextbox *textbox) { |
385 GtkWidget *widget = GTK_WIDGET (textbox); | 385 GtkWidget *widget = GTK_WIDGET (textbox); |
386 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | 386 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); |
387 priv->double_size = !priv->double_size; | 387 priv->double_size = !priv->double_size; |
388 | 388 |
389 gtk_widget_set_size_request(widget, textbox->weight*(1+priv->double_size), textbox->height*(1+priv->double_size)); | 389 gtk_widget_set_size_request(widget, priv->w*(1+priv->double_size), textbox->height*(1+priv->double_size)); |
390 gtk_widget_set_uposition(widget, textbox->x*(1+priv->double_size), textbox->y*(1+priv->double_size)); | 390 gtk_widget_set_uposition(widget, textbox->x*(1+priv->double_size), textbox->y*(1+priv->double_size)); |
391 | 391 |
392 textbox->redraw = TRUE; | 392 textbox->redraw = TRUE; |
393 } | 393 } |
394 | 394 |
408 if (priv->pixmap) { | 408 if (priv->pixmap) { |
409 if (skin_get_id() != priv->skin_id) { | 409 if (skin_get_id() != priv->skin_id) { |
410 priv->skin_id = skin_get_id(); | 410 priv->skin_id = skin_get_id(); |
411 textbox_generate_pixmap(textbox); | 411 textbox_generate_pixmap(textbox); |
412 } | 412 } |
413 obj = gdk_pixmap_new(NULL, textbox->weight, textbox->height, gdk_rgb_get_visual()->depth); | 413 obj = gdk_pixmap_new(NULL, priv->w, textbox->height, gdk_rgb_get_visual()->depth); |
414 src = priv->pixmap; | 414 src = priv->pixmap; |
415 | 415 |
416 cw = priv->pixmap_width - priv->offset; | 416 cw = priv->pixmap_width - priv->offset; |
417 if (cw > textbox->weight) | 417 if (cw > priv->w) |
418 cw = textbox->weight; | 418 cw = priv->w; |
419 gdk_draw_drawable(obj, priv->gc, src, priv->offset, 0, 0, 0, cw, textbox->height); | 419 gdk_draw_drawable(obj, priv->gc, src, priv->offset, 0, 0, 0, cw, textbox->height); |
420 if (cw < textbox->weight) | 420 if (cw < priv->w) |
421 gdk_draw_drawable(obj, priv->gc, src, 0, 0, | 421 gdk_draw_drawable(obj, priv->gc, src, 0, 0, |
422 textbox->x + cw, textbox->y, | 422 textbox->x + cw, textbox->y, |
423 textbox->weight - cw, textbox->height); | 423 priv->w - cw, textbox->height); |
424 | 424 |
425 if (priv->double_size) { | 425 if (priv->double_size) { |
426 GdkImage *img, *img2x; | 426 GdkImage *img, *img2x; |
427 img = gdk_drawable_get_image(obj, 0, 0, textbox->weight, textbox->height); | 427 img = gdk_drawable_get_image(obj, 0, 0, priv->w, textbox->height); |
428 img2x = create_dblsize_image(img); | 428 img2x = create_dblsize_image(img); |
429 gtk_image_set(GTK_IMAGE(priv->image), img2x, NULL); | 429 gtk_image_set(GTK_IMAGE(priv->image), img2x, NULL); |
430 g_object_unref(img2x); | 430 g_object_unref(img2x); |
431 g_object_unref(img); | 431 g_object_unref(img); |
432 } else | 432 } else |
438 } | 438 } |
439 } | 439 } |
440 | 440 |
441 static void ui_skinned_textbox_redraw(UiSkinnedTextbox *textbox) { | 441 static void ui_skinned_textbox_redraw(UiSkinnedTextbox *textbox) { |
442 textbox->redraw = TRUE; | 442 textbox->redraw = TRUE; |
443 gint w, h; | |
444 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
445 gtk_widget_get_size_request(GTK_WIDGET(textbox), &w, &h); | |
446 if (w != textbox->weight || h != textbox->height) | |
447 gtk_widget_set_size_request(GTK_WIDGET(textbox), textbox->weight, textbox->height); | |
448 ui_skinned_textbox_paint(textbox); | 443 ui_skinned_textbox_paint(textbox); |
449 } | 444 } |
450 | 445 |
451 static gboolean ui_skinned_textbox_should_scroll(UiSkinnedTextbox *textbox) { | 446 static gboolean ui_skinned_textbox_should_scroll(UiSkinnedTextbox *textbox) { |
452 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | 447 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); |
455 | 450 |
456 if (priv->font) { | 451 if (priv->font) { |
457 gint width; | 452 gint width; |
458 text_get_extents(priv->fontname, textbox->text, &width, NULL, NULL, NULL); | 453 text_get_extents(priv->fontname, textbox->text, &width, NULL, NULL, NULL); |
459 | 454 |
460 if (width <= textbox->weight) | 455 if (width <= priv->w) |
461 return FALSE; | 456 return FALSE; |
462 else | 457 else |
463 return TRUE; | 458 return TRUE; |
464 } | 459 } |
465 | 460 |
466 if (g_utf8_strlen(textbox->text, -1) * bmp_active_skin->properties.textbox_bitmap_font_width > textbox->weight) | 461 if (g_utf8_strlen(textbox->text, -1) * bmp_active_skin->properties.textbox_bitmap_font_width > priv->w) |
467 return TRUE; | 462 return TRUE; |
468 | 463 |
469 return FALSE; | 464 return FALSE; |
470 } | 465 } |
471 | 466 |
543 | 538 |
544 length = g_utf8_strlen(pixmaptext, -1); | 539 length = g_utf8_strlen(pixmaptext, -1); |
545 | 540 |
546 text_get_extents(priv->fontname, pixmaptext, &width, NULL, NULL, NULL); | 541 text_get_extents(priv->fontname, pixmaptext, &width, NULL, NULL, NULL); |
547 | 542 |
548 priv->pixmap_width = MAX(width, textbox->weight); | 543 priv->pixmap_width = MAX(width, priv->w); |
549 priv->pixmap = gdk_pixmap_new(mainwin->window, priv->pixmap_width, | 544 priv->pixmap = gdk_pixmap_new(mainwin->window, priv->pixmap_width, |
550 textbox->height, | 545 textbox->height, |
551 gdk_rgb_get_visual()->depth); | 546 gdk_rgb_get_visual()->depth); |
552 gc = priv->gc; | 547 gc = priv->gc; |
553 c = skin_get_color(bmp_active_skin, SKIN_TEXTBG); | 548 c = skin_get_color(bmp_active_skin, SKIN_TEXTBG); |
591 | 586 |
592 if (!priv->is_dragging) { | 587 if (!priv->is_dragging) { |
593 if (priv->scroll_back) priv->offset -= 1; | 588 if (priv->scroll_back) priv->offset -= 1; |
594 else priv->offset += 1; | 589 else priv->offset += 1; |
595 | 590 |
596 if (priv->offset >= (priv->pixmap_width - textbox->weight)) { | 591 if (priv->offset >= (priv->pixmap_width - priv->w)) { |
597 priv->scroll_back = TRUE; | 592 priv->scroll_back = TRUE; |
598 /* There are 1 million microseconds per second */ | 593 /* There are 1 million microseconds per second */ |
599 //g_usleep(1000000); | 594 //g_usleep(1000000); |
600 } | 595 } |
601 if (priv->offset <= 0) { | 596 if (priv->offset <= 0) { |
635 | 630 |
636 /* | 631 /* |
637 * wl is the number of (partial) letters visible. Only makes | 632 * wl is the number of (partial) letters visible. Only makes |
638 * sense when using skinned font. | 633 * sense when using skinned font. |
639 */ | 634 */ |
640 wl = textbox->weight / 5; | 635 wl = priv->w / 5; |
641 if (wl * 5 != textbox->weight) | 636 if (wl * 5 != priv->w) |
642 wl++; | 637 wl++; |
643 | 638 |
644 length = g_utf8_strlen(textbox->text, -1); | 639 length = g_utf8_strlen(textbox->text, -1); |
645 | 640 |
646 priv->is_scrollable = FALSE; | 641 priv->is_scrollable = FALSE; |
848 void ui_skinned_textbox_move_relative(GtkWidget *widget, gint x, gint y) { | 843 void ui_skinned_textbox_move_relative(GtkWidget *widget, gint x, gint y) { |
849 UiSkinnedTextbox *t = UI_SKINNED_TEXTBOX(widget); | 844 UiSkinnedTextbox *t = UI_SKINNED_TEXTBOX(widget); |
850 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (widget); | 845 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (widget); |
851 gtk_fixed_move(GTK_FIXED(priv->fixed), widget, t->x+x, t->y+y); | 846 gtk_fixed_move(GTK_FIXED(priv->fixed), widget, t->x+x, t->y+y); |
852 } | 847 } |
848 | |
849 void ui_skinned_textbox_resize_relative(GtkWidget *widget, gint w, gint h) { | |
850 UiSkinnedTextbox *t = UI_SKINNED_TEXTBOX(widget); | |
851 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (widget); | |
852 gtk_widget_set_size_request(widget, priv->w+w, t->height+h); | |
853 } |