Changeset 212:8ab606c00520
- Timestamp:
- 04/06/08 14:26:37
(5 months ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
Fix side effects in getter methods
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r158 |
r212 |
|
| 29 | 29 | import tango.stdc.stringz; |
|---|
| 30 | 30 | import tango.util.Convert; |
|---|
| 31 | | import Math = tango.math.Math; |
|---|
| 32 | | static import tango.stdc.string; |
|---|
| 33 | | static import tango.text.Util; |
|---|
| 34 | | import Unicode = tango.text.Unicode; |
|---|
| | 31 | import dwt.dwthelper.utils; |
|---|
| | 32 | alias char[] String; |
|---|
| 35 | 33 | |
|---|
| 36 | 34 | /** |
|---|
| … | … | |
| 204 | 202 | if (wHint !is DWT.DEFAULT && wHint < 0) wHint = 0; |
|---|
| 205 | 203 | if (hHint !is DWT.DEFAULT && hHint < 0) hHint = 0; |
|---|
| 206 | | int w, h; |
|---|
| | 204 | int[1] w, h; |
|---|
| 207 | 205 | OS.gtk_widget_realize (handle); |
|---|
| 208 | 206 | auto layout = OS.gtk_entry_get_layout (cast(GtkEntry*)handle); |
|---|
| … | … | |
| 210 | 208 | int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); |
|---|
| 211 | 209 | for (int i = 0; i < digits; i++) adjustment.upper *= 10; |
|---|
| 212 | | char[] string = to!(char[])( (cast(int) adjustment.upper) ); |
|---|
| | 210 | String string = to!(String)( (cast(int) adjustment.upper) ); |
|---|
| 213 | 211 | if (digits > 0) { |
|---|
| 214 | 212 | //PROTING_TODO: Efficiency |
|---|
| 215 | | char[] buffer = string ~ getDecimalSeparator (); |
|---|
| | 213 | String buffer = string ~ getDecimalSeparator (); |
|---|
| 216 | 214 | int count = digits - string.length; |
|---|
| 217 | 215 | while (count >= 0) { |
|---|
| … | … | |
| 223 | 221 | char [] buffer1 = string; |
|---|
| 224 | 222 | auto ptr = OS.pango_layout_get_text (layout); |
|---|
| 225 | | char[] buffer2 = fromStringz( ptr ).dup; |
|---|
| | 223 | String buffer2 = fromStringz( ptr ).dup; |
|---|
| 226 | 224 | OS.pango_layout_set_text (layout, buffer1.ptr, buffer1.length); |
|---|
| 227 | | OS.pango_layout_get_size (layout, &w, &h); |
|---|
| | 225 | OS.pango_layout_get_size (layout, w.ptr, h.ptr); |
|---|
| 228 | 226 | OS.pango_layout_set_text (layout, buffer2.ptr, buffer2.length); |
|---|
| 229 | | int width = OS.PANGO_PIXELS (w); |
|---|
| 230 | | int height = OS.PANGO_PIXELS (h); |
|---|
| | 227 | int width = OS.PANGO_PIXELS (w [0]); |
|---|
| | 228 | int height = OS.PANGO_PIXELS (h [0]); |
|---|
| 231 | 229 | width = wHint is DWT.DEFAULT ? width : wHint; |
|---|
| 232 | 230 | height = hHint is DWT.DEFAULT ? height : hHint; |
|---|
| … | … | |
| 392 | 390 | auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); |
|---|
| 393 | 391 | int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); |
|---|
| 394 | | for (int i = 0; i < digits; i++) adjustment.step_increment *= 10; |
|---|
| 395 | | return cast(int) (adjustment.step_increment + 0.5); |
|---|
| | 392 | auto value = adjustment.step_increment; |
|---|
| | 393 | for (int i = 0; i < digits; i++) value *= 10; |
|---|
| | 394 | return cast(int) (value + 0.5); |
|---|
| 396 | 395 | } |
|---|
| 397 | 396 | |
|---|
| … | … | |
| 410 | 409 | auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); |
|---|
| 411 | 410 | int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); |
|---|
| 412 | | for (int i = 0; i < digits; i++) adjustment.upper *= 10; |
|---|
| 413 | | return cast(int) (adjustment.upper + 0.5); |
|---|
| | 411 | auto value = adjustment.upper; |
|---|
| | 412 | for (int i = 0; i < digits; i++) value *= 10; |
|---|
| | 413 | return cast(int) (value + 0.5); |
|---|
| 414 | 414 | } |
|---|
| 415 | 415 | |
|---|
| … | … | |
| 428 | 428 | auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); |
|---|
| 429 | 429 | int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); |
|---|
| 430 | | for (int i = 0; i < digits; i++) adjustment.lower *= 10; |
|---|
| 431 | | return cast(int) (adjustment.lower + 0.5); |
|---|
| | 430 | auto value = adjustment.lower; |
|---|
| | 431 | for (int i = 0; i < digits; i++) value *= 10; |
|---|
| | 432 | return cast(int) (value + 0.5); |
|---|
| 432 | 433 | } |
|---|
| 433 | 434 | |
|---|
| … | … | |
| 447 | 448 | auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); |
|---|
| 448 | 449 | int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); |
|---|
| 449 | | for (int i = 0; i < digits; i++) adjustment.page_increment *= 10; |
|---|
| 450 | | return cast(int) (adjustment.page_increment + 0.5); |
|---|
| | 450 | auto value = adjustment.page_increment; |
|---|
| | 451 | for (int i = 0; i < digits; i++) value *= 10; |
|---|
| | 452 | return cast(int) (value + 0.5); |
|---|
| 451 | 453 | } |
|---|
| 452 | 454 | |
|---|
| … | … | |
| 465 | 467 | auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); |
|---|
| 466 | 468 | int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); |
|---|
| 467 | | for (int i = 0; i < digits; i++) adjustment.value *= 10; |
|---|
| 468 | | return cast(int) (adjustment.value + 0.5); |
|---|
| | 469 | auto value = adjustment.value; |
|---|
| | 470 | for (int i = 0; i < digits; i++) value *= 10; |
|---|
| | 471 | return cast(int) (value + 0.5); |
|---|
| 469 | 472 | } |
|---|
| 470 | 473 | |
|---|
| … | … | |
| 484 | 487 | } |
|---|
| 485 | 488 | |
|---|
| 486 | | char[] getDecimalSeparator () { |
|---|
| | 489 | String getDecimalSeparator () { |
|---|
| 487 | 490 | auto ptr = OS.localeconv_decimal_point (); |
|---|
| 488 | 491 | return fromStringz( ptr ).dup; |
|---|
| … | … | |
| 571 | 574 | override int /*long*/ gtk_delete_text (GtkWidget* widget, int start_pos, int end_pos) { |
|---|
| 572 | 575 | if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return 0; |
|---|
| 573 | | char[] newText = verifyText ("", cast(int)/*64*/start_pos, cast(int)/*64*/end_pos); |
|---|
| | 576 | String newText = verifyText ("", cast(int)/*64*/start_pos, cast(int)/*64*/end_pos); |
|---|
| 574 | 577 | if (newText is null) { |
|---|
| 575 | 578 | OS.g_signal_stop_emission_by_name (handle, OS.delete_text.ptr); |
|---|
| … | … | |
| 602 | 605 | // if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return 0; |
|---|
| 603 | 606 | if (new_text is null || new_text_length is 0) return 0; |
|---|
| 604 | | char[] oldText = new_text[ 0 .. new_text_length ].dup; |
|---|
| | 607 | String oldText = new_text[ 0 .. new_text_length ].dup; |
|---|
| 605 | 608 | int pos; |
|---|
| 606 | 609 | pos = position; |
|---|
| … | … | |
| 609 | 612 | pos = cast(int)/*64*/OS.g_utf8_strlen (ptr, -1); |
|---|
| 610 | 613 | } |
|---|
| 611 | | char[] newText = verifyText (oldText, pos, pos); |
|---|
| | 614 | String newText = verifyText (oldText, pos, pos); |
|---|
| 612 | 615 | if (newText !is oldText) { |
|---|
| 613 | 616 | int newStart, newEnd; |
|---|
| … | … | |
| 1025 | 1028 | } |
|---|
| 1026 | 1029 | |
|---|
| 1027 | | char[] verifyText (char[] string, int start, int end) { |
|---|
| | 1030 | String verifyText (String string, int start, int end) { |
|---|
| 1028 | 1031 | if (string.length is 0 && start is end) return null; |
|---|
| 1029 | 1032 | Event event = new Event (); |
|---|
| … | … | |
| 1044 | 1047 | int index = 0; |
|---|
| 1045 | 1048 | if (OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle) > 0) { |
|---|
| 1046 | | char[] decimalSeparator = getDecimalSeparator (); |
|---|
| 1047 | | index = tango.text.Util.locatePattern( string, decimalSeparator ); |
|---|
| 1048 | | if (index !is string.length) { |
|---|
| 1049 | | string = string[ 0 .. index ] ~ string[ index + 1 ]; |
|---|
| | 1049 | String decimalSeparator = getDecimalSeparator (); |
|---|
| | 1050 | index = string.indexOf( decimalSeparator ); |
|---|
| | 1051 | if (index !is -1 ) { |
|---|
| | 1052 | string = string.substring( 0, index ) ~ string.substring( index + 1 ); |
|---|
| 1050 | 1053 | } |
|---|
| 1051 | 1054 | index = 0; |
|---|
| 1052 | 1055 | } |
|---|
| 1053 | 1056 | while (index < string.length) { |
|---|
| 1054 | | if (!Unicode.isDigit (string[index])) break; |
|---|
| | 1057 | if (!CharacterIsDigit (string.charAt(index))) break; |
|---|
| 1055 | 1058 | index++; |
|---|
| 1056 | 1059 | } |
|---|