* Insert a widget into a list of widgets. * @param w1 Widget to which the other widget is added. * @param w2 Widget which is added to the first widget (ordered by index). * @return The first widget of the chain. */
| 913 | * @return The first widget of the chain. |
| 914 | */ |
| 915 | Widget *GUI_Widget_Insert(Widget *w1, Widget *w2) |
| 916 | { |
| 917 | Widget *first; |
| 918 | Widget *prev; |
| 919 | |
| 920 | if (w1 == NULL) return w2; |
| 921 | if (w2 == NULL) return w1; |
| 922 | |
| 923 | if (w2->index <= w1->index) { |
| 924 | w2->next = w1; |
| 925 | return w2; |
| 926 | } |
| 927 | |
| 928 | first = w1; |
| 929 | prev = w1; |
| 930 | |
| 931 | while (w2->index > w1->index && w1->next != NULL) { |
| 932 | prev = w1; |
| 933 | w1 = w1->next; |
| 934 | } |
| 935 | |
| 936 | if (w2->index > w1->index) { |
| 937 | w1 = GUI_Widget_Link(first, w2); |
| 938 | } else { |
| 939 | prev->next = w2; |
| 940 | w2->next = w1; |
| 941 | } |
| 942 | |
| 943 | s_widgetReset = true; |
| 944 | |
| 945 | return first; |
| 946 | } |
| 947 | |
| 948 | /** |
| 949 | * Select a widget as current widget. |
no test coverage detected