diff --git a/src/render/opengl.cpp b/src/render/opengl.cpp index bb4164f..6de791a 100644 --- a/src/render/opengl.cpp +++ b/src/render/opengl.cpp @@ -180,17 +180,6 @@ Shader CreateShader(char *glsl_vshader, char *glsl_fshader) { return result; } -#define SLL_QUEUE_ADD_MOD(f, l, n, next) \ - do { \ - (n)->next = 0; \ - if ((f) == 0) { \ - (f) = (l) = (n); \ - } else { \ - (l) = (l)->next = (n); \ - } \ - } while (0) -#define SLL_QUEUE_ADD(f, l, n) SLL_QUEUE_ADD_MOD(f, l, n, next) - VertexNode2D *AllocVertexNode2D(Allocator allocator, VertexList2D *list) { VertexNode2D *node = AllocType(allocator, VertexNode2D); SLL_QUEUE_ADD(list->first, list->last, node); diff --git a/src/text_editor/buffer.h b/src/text_editor/buffer.h index bc066ee..84cee70 100644 --- a/src/text_editor/buffer.h +++ b/src/text_editor/buffer.h @@ -16,6 +16,8 @@ struct HistoryEntry { struct Buffer { BufferID id; + Buffer *next; + Buffer *prev; String name; Int change_id; Int user_change_id; diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 75b33cb..e0492f2 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -82,9 +82,8 @@ void Command_ListBuffers() { Scratch scratch; Array strings = {scratch}; - For(Buffers) { - Buffer *buffer = GetBuffer(it); - String string = Format(scratch, "%.*s", FmtString(buffer->name)); + for (Buffer *it = FirstBuffer; it; it = it->next) { + String string = Format(scratch, "%.*s", FmtString(it->name)); Add(&strings, string); } String result = Merge(scratch, strings, "\n"); @@ -145,8 +144,7 @@ void Command_Append(View *view, String16 string, bool scroll_to_end_if_cursor_on }; Array view_info = {scratch}; - For (Views) { - View *it_view = GetView(it); + for (View *it_view = FirstView; it_view; it_view = it_view->next) { if (it_view->active_buffer != buffer->id) { continue; } @@ -200,7 +198,7 @@ void ReportErrorf(const char *fmt, ...) { // Set console view as active { - Window *w = GetWindowWithView(NullViewID); + Window *w = GetWindow(NullWindowID); if (!w) { BSet bset = GetActiveMainSet(); w = GetNextLayoutWindow(bset.window); @@ -229,7 +227,7 @@ void ReportWarningf(const char *fmt, ...) { // Set console view as active { - Window *w = GetWindowWithView(NullViewID); + Window *w = GetWindow(NullWindowID); if (!w) { BSet bset = GetActiveMainSet(); w = GetNextLayoutWindow(bset.window); diff --git a/src/text_editor/commands_bindings.cpp b/src/text_editor/commands_bindings.cpp index 1565391..84b5422 100644 --- a/src/text_editor/commands_bindings.cpp +++ b/src/text_editor/commands_bindings.cpp @@ -109,7 +109,7 @@ void OnCommand(Event event) { // Window cursor setting // Scratch scratch; - Array order = GetWindowZOrder(scratch); + Array order = GetWindowZOrder(scratch); { static SDL_Cursor *SDL_MouseCursor; if (SDL_MouseCursor) { @@ -119,10 +119,9 @@ void OnCommand(Event event) { Vec2I mouse = MouseVec2I(); For(order) { - Window *window = Windows[it].o; - if (!window->visible) continue; - bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect); - bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect); + if (!it->visible) continue; + bool mouse_in_total = CheckCollisionPointRec(mouse, it->total_rect); + bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, it->scrollbar_rect); if (!IsDocumentSelectionValid() && (mouse_in_scrollbar || IsScrollbarSelectionValid())) { SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT); @@ -146,12 +145,11 @@ void OnCommand(Event event) { Vec2I mouse = MouseVec2I(); For(order) { - Window *window = Windows[it].o; - if (!window->visible) continue; + if (!it->visible) continue; - bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect); + bool mouse_in_window = CheckCollisionPointRec(mouse, it->total_rect); if (mouse_in_window) { - View *view = GetView(window->active_view); + View *view = GetView(it->active_view); view->scroll.y -= (Int)(event.ywheel * 48); view->scroll.x += (Int)(event.xwheel * 48); break; @@ -212,11 +210,12 @@ void OnCommand(Event event) { if (MousePress()) { Vec2I mouse = MouseVec2I(); For(order) { - Window *window = Windows[it].o; - if (!window->visible) continue; - bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect); + if (!it->visible) { + continue; + } + bool mouse_in_document = CheckCollisionPointRec(mouse, it->document_rect); if (mouse_in_document) { - ActiveWindow = window->id; + ActiveWindow = it->id; break; } } @@ -313,22 +312,21 @@ void OnCommand(Event event) { // @todo: it generally works ok but it moves the scrollbar a bit on click // when mouse is not even moving For(order) { - Window *window = Windows[it].o; - if (!window->visible) continue; - bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect); + if (!it->visible) continue; + bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, it->scrollbar_rect); if (mouse_in_scrollbar) { - ScrollbarSelected = window->id; + ScrollbarSelected = it->id; - View *view = GetView(window->active_view); + View *view = GetView(it->active_view); Vec2 mouse_vec2 = MouseVec2(); - Scroller s = ComputeScrollerRect(window); - double size_y = (double)GetSize(window->scrollbar_rect).y; - double p = mouse_vec2.y - window->scrollbar_rect.min.y; + Scroller s = ComputeScrollerRect(it); + double size_y = (double)GetSize(it->scrollbar_rect).y; + double p = mouse_vec2.y - it->scrollbar_rect.min.y; if (mouse_vec2.y < s.rect.min.y || mouse_vec2.y > s.rect.max.y) { view->scroll.y = (Int)(p / size_y * (double)s.line_count * (double)FontLineSpacing); - window->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y; + it->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y; } else { - window->mouse_scroller_offset = (s.rect.min.y - p) / size_y; + it->mouse_scroller_offset = (s.rect.min.y - p) / size_y; } break; } diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index 472dc33..62176b3 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -286,12 +286,12 @@ int Lua_ListBuffers(lua_State *L) { } int Lua_GetBufferList(lua_State *L) { - lua_createtable(L, 0, (int)Buffers.len); + lua_createtable(L, 0, (int)BufferCount); int i = 1; - For(Buffers) { + for (Buffer *it = FirstBuffer; it; it = it->next) { lua_pushinteger(L, i++); - lua_pushlstring(L, it.o->name.data, it.o->name.len); + lua_pushlstring(L, it->name.data, it->name.len); lua_settable(L, -3); /* 3rd element from the stack top */ } /* We still have table left on top of the Lua stack. */ @@ -301,7 +301,7 @@ int Lua_GetBufferList(lua_State *L) { int Lua_BufferExists(lua_State *L) { String string = lua_tostring(L, 1); lua_pop(L, 1); - Buffer *buffer = BufferNameExists(string); + Buffer *buffer = GetBuffer(string); lua_pushboolean(L, buffer != NULL); return 1; } @@ -531,11 +531,12 @@ void ReloadLuaConfigs() { ReloadStyle(); ReloadFont(); - For(Windows) { - Window *window = it.o; - if (!window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue; - window->draw_scrollbar = StyleDrawScrollbar; - window->draw_line_numbers = StyleDrawLineNumbers; + for (Window *it = FirstWindow; it; it = it->next) { + if (!it->visible || it->absolute_position || it->is_title_bar || it->is_search_bar) { + continue; + } + it->draw_scrollbar = StyleDrawScrollbar; + it->draw_line_numbers = StyleDrawLineNumbers; } } diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index 9a7fbdb..7fc9313 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -2,9 +2,17 @@ WindowID WindowIDs; BufferID BufferIDs; ViewID ViewIDs; -Array Buffers; -Array Views; -Array Windows; +Window *FirstWindow; +Window *LastWindow; +Int WindowCount; + +View *FirstView; +View *LastView; +Int ViewCount; + +Buffer *FirstBuffer; +Buffer *LastBuffer; +Int BufferCount; BufferID NullBufferID; // +buffer ViewID NullViewID; @@ -68,38 +76,45 @@ inline WindowID AllocWindowID(Window *window) { return {WindowIDs.id++, window}; inline BufferID AllocBufferID(Buffer *buffer) { return {BufferIDs.id++, buffer}; } inline Window *GetWindow(WindowID id) { - For(Windows) if (it == id) return it.o; - return Windows[0].o; + for (Window *it = FirstWindow; it; it = it->next) { + if (it->id == id) return it; + } + return FirstWindow; } inline Buffer *GetBuffer(BufferID id) { - For(Buffers) if (it == id) return it.o; - return Buffers[0].o; + for (Buffer *it = FirstBuffer; it; it = it->next) { + if (it->id == id) return it; + } + return FirstBuffer; } inline Buffer *GetBufferStrict(BufferID id) { - For(Buffers) if (it == id) return it.o; + for (Buffer *it = FirstBuffer; it; it = it->next) { + if (it->id == id) return it; + } return NULL; } inline Buffer *GetBuffer(String name) { - For(Buffers) if (it.o->name == name) return it.o; - return Buffers[0].o; + for (Buffer *it = FirstBuffer; it; it = it->next) { + if (it->name == name) return it; + } + return FirstBuffer; } inline Buffer *GetBufferStrict(String name) { - For(Buffers) if (it.o->name == name) return it.o; - return NULL; -} - -inline Buffer *BufferNameExists(String name) { - For(Buffers) if (it.o->name == name) return it.o; + for (Buffer *it = FirstBuffer; it; it = it->next) { + if (it->name == name) return it; + } return NULL; } inline View *GetView(ViewID id) { - For(Views) if (it == id) return it.o; - return Views[0].o; + for (View *it = FirstView; it; it = it->next) { + if (it->id == id) return it; + } + return FirstView; } inline bool IsNull(Buffer *buffer) { return buffer->id.id == NullBufferID.id; } @@ -119,7 +134,8 @@ void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 409 Buffer *CreateBuffer(Allocator allocator, String name, Int size) { Buffer *result = AllocType(allocator, Buffer); InitBuffer(allocator, result, name, size); - Add(&Buffers, result->id); + DLL_QUEUE_ADD(FirstBuffer, LastBuffer, result); + BufferCount += 1; return result; } @@ -131,13 +147,14 @@ Buffer *CreateTempBuffer(Allocator allocator, Int size = 4096) { return result; } -Window *CreateWindow(bool insert_into_windows = true) { +Window *CreateWindow() { Window *w = AllocType(Perm, Window); w->visible = true; w->draw_scrollbar = StyleDrawScrollbar; w->draw_line_numbers = StyleDrawLineNumbers; w->id = AllocWindowID(w); - if (insert_into_windows) Add(&Windows, w->id); + DLL_QUEUE_ADD(FirstWindow, LastWindow, w); + WindowCount += 1; return w; } @@ -148,49 +165,56 @@ View *CreateView(BufferID active_buffer) { view->active_buffer = active_buffer; view->carets.allocator = al; Add(&view->carets, {0, 0}); - Add(&Views, view->id); + DLL_QUEUE_ADD(FirstView, LastView, view); + ViewCount += 1; return view; } -View *FindView(BufferID buffer_id) { - For(Views) { - View *view = it.o; - if (view->active_buffer == buffer_id) { - return view; +View *FindView(BufferID buffer_id, View *default_view = NULL) { + for (View *it = FirstView; it; it = it->next) { + if (it->active_buffer == buffer_id) { + return it; } } - return NULL; + return default_view; } -Window *GetWindowWithView(ViewID view_id) { - For(Windows) { - Window *window = it.o; - if (window->active_view.id == view_id.id) { - return window; +Window *FindWindow(ViewID view_id, Window *default_window = NULL) { + for (Window *it = FirstWindow; it; it = it->next) { + if (it->active_view == view_id) { + return it; } } - return NULL; + return default_window; } -Window *GetWindowWithView(String buffer_name) { - For(Windows) { - View *it_view = GetView(it.o->active_view); +Window *FindWindow(String buffer_name, Window *default_window = NULL) { + for (Window *it = FirstWindow; it; it = it->next) { + View *it_view = GetView(it->active_view); Buffer *it_buffer = GetBuffer(it_view->active_buffer); if (it_buffer->name == buffer_name) { - return it.o; + return it; } } + return default_window; +} + +Window *FindWindow(BufferID buffer_id) { + for (Window *it = FirstWindow; it; it = it->next) { + View *view = GetView(it->active_view); + if (view->active_buffer == buffer_id) return it; + } return NULL; } -View *FindViewWithBufferName(String name) { - For(Views) { - Buffer *buffer = GetBuffer(it.o->active_buffer); +View *FindView(String name, View *default_view = NULL) { + for (View *it = FirstView; it; it = it->next) { + Buffer *buffer = GetBuffer(it->active_buffer); if (buffer->name == name) { - return it.o; + return it; } } - return NULL; + return default_view; } Window *GetTitlebarWindow(WindowID id) { @@ -379,14 +403,14 @@ View *OpenBufferView(String name) { } View *WindowOpenBufferView(Window *new_parent_window, String name) { - View *view = FindViewWithBufferName(name); + View *view = FindView(name); if (!view) { View *result = OpenBufferView(name); new_parent_window->active_view = result->id; return result; } - Window *window = GetWindowWithView(view->id); + Window *window = FindWindow(view->id); if (!window) { new_parent_window->active_view = view->id; return view; @@ -402,34 +426,18 @@ View *WindowOpenBufferView(Window *new_parent_window, String name) { } Window *ViewIsReferenced(ViewID view) { - For(Windows) { - Window *window = it.o; - if (window->active_view == view) return window; - if (window->active_goto_list == view) return window; + for (Window *it = FirstWindow; it; it = it->next) { + if (it->active_view == view || it->active_goto_list == view) return it; } return NULL; } View *BufferIsReferenced(BufferID buffer_id) { - For(Views) { - View *view = it.o; - if (view->active_buffer == buffer_id) return view; - } - return NULL; -} - -Window *BufferIsInWindow(BufferID buffer_id) { - For(Windows) { - Window *window = it.o; - View *view = GetView(window->active_view); - if (view->active_buffer == buffer_id) return window; - } - return NULL; + return FindView(buffer_id); } Window *BufferIsCrumb(BufferID buffer_id) { - For(Windows) { - Window *window = it.o; + for (Window *window = FirstWindow; window; window = window->next) { For(window->goto_history) if (it.buffer_id == buffer_id) return window; For(window->goto_redo) if (it.buffer_id == buffer_id) return window; } @@ -458,12 +466,11 @@ void GarbageCollect() { // } // } - For(Buffers) { - Buffer *buffer = GetBuffer(it); - if (buffer->file_mod_time) { - int64_t new_file_mod_time = GetFileModTime(buffer->name); - if (buffer->file_mod_time != new_file_mod_time) { - buffer->changed_on_disk = true; + for (Buffer *it = FirstBuffer; it; it = it->next) { + if (it->file_mod_time) { + int64_t new_file_mod_time = GetFileModTime(it->name); + if (it->file_mod_time != new_file_mod_time) { + it->changed_on_disk = true; } } } diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 4e92f62..dc4ee84 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -1,5 +1,6 @@ #include + #define BASIC_IMPL #include "basic/basic.h" #include "basic/filesystem.h" @@ -7,6 +8,7 @@ #include "basic/math_int.cpp" #include "basic/math.cpp" #include "profiler/profiler.cpp" +#include "build_tool/standalone_libraries/linked_list.h" #include "SDL3/SDL.h" #include "external/glad/glad.h" @@ -163,17 +165,16 @@ void Update(Event event) { LayoutWindows(event.xwindow, event.ywindow); Scratch scratch; - Array order = GetWindowZOrder(scratch); + Array order = GetWindowZOrder(scratch); For(order) { - Window *window = Windows[it].o; - if (!window->visible) continue; - View *view = GetView(window->active_view); + if (!it->visible) continue; + View *view = GetView(it->active_view); view->main_caret_on_begin_frame = view->carets[0]; view->update_scroll = true; } OnCommand(event); - For(Windows) if (it.o->is_title_bar) ReplaceTitleBarData(it.o); + for (Window *it = FirstWindow; it; it = it->next) if (it->is_title_bar) ReplaceTitleBarData(it); UpdateProcesses(); UpdateCo(&event); ReloadLuaConfigs(); @@ -182,11 +183,10 @@ void Update(Event event) { GarbageCollect(); For(IterateInReverse(&order)) { - Window *window = Windows[it].o; - if (!window->visible) continue; + if (!it->visible) continue; - View *view = GetView(window->active_view); - UpdateScroll(window, !AreEqual(view->main_caret_on_begin_frame, view->carets[0]) && view->update_scroll); + View *view = GetView(it->active_view); + UpdateScroll(it, !AreEqual(view->main_caret_on_begin_frame, view->carets[0]) && view->update_scroll); } } @@ -408,11 +408,10 @@ int main(int argc, char **argv) Event *event = GetLast(frame_events); LayoutWindows(event->xwindow, event->ywindow); // This is here to render changes in title bar size without a frame of delay BeginFrameRender(event->xwindow, event->ywindow); - Array order = GetWindowZOrder(scratch); + Array order = GetWindowZOrder(scratch); For(IterateInReverse(&order)) { - Window *window = Windows[it].o; - if (!window->visible) continue; - DrawWindow(window, *GetLast(frame_events)); + if (!it->visible) continue; + DrawWindow(it, *GetLast(frame_events)); } EndFrameRender(event->xwindow, event->ywindow, ColorBackground); SDL_GL_SwapWindow(SDLWindow); diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 9d41edb..816d0eb 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -5,6 +5,8 @@ struct WindowID { Int id; Window *o; }; // @todo: change name of object to somet struct View { ViewID id; BufferID active_buffer; + View *next; + View *prev; Vec2I scroll; Array carets; @@ -21,6 +23,8 @@ struct GotoCrumb { struct Window { WindowID id; ViewID active_view; + Window *next; + Window *prev; WindowID title_bar_window; Int title_bar_last_buffer_change_id; // @todo: bring back the changes to title bar? diff --git a/src/text_editor/title_bar.cpp b/src/text_editor/title_bar.cpp index e2b940d..3dd8eef 100644 --- a/src/text_editor/title_bar.cpp +++ b/src/text_editor/title_bar.cpp @@ -15,7 +15,6 @@ void UpdateDebugBuffer() { float xmouse, ymouse; SDL_GetMouseState(&xmouse, &ymouse); RawAppendf(buffer, "mouse: [%f, %f]\n", xmouse, ymouse); - RawAppendf(buffer, "window count: %d view count: %d buffer count: %d\n", (int)Windows.len, (int)Views.len, (int)Buffers.len); RawAppendf(buffer, "C:/Work/text_editor/src/text_editor/text_editor.cpp\n"); RawAppendf(buffer, "working dir: %.*s\n", FmtString(WorkingDir)); RawAppendf(buffer, "exe dir: %.*s\n", FmtString(ExeDir)); diff --git a/src/text_editor/window.cpp b/src/text_editor/window.cpp index f21cb58..3f380d9 100644 --- a/src/text_editor/window.cpp +++ b/src/text_editor/window.cpp @@ -5,17 +5,18 @@ struct VisualColumn { Array GetVisualColumns(Allocator allocator) { Array columns = {allocator}; - For(Windows) { - Window *window = it.o; - if (!window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue; + for (Window *it = FirstWindow; it; it = it->next) { + if (!it->visible || it->absolute_position || it->is_title_bar || it->is_search_bar) { + continue; + } - if (window->is_column) { - Add(&columns, {window, {allocator}}); + if (it->is_column) { + Add(&columns, {it, {allocator}}); VisualColumn *col = GetLast(columns); - Add(&col->rows, window); + Add(&col->rows, it); } else if (columns.len) { VisualColumn *col = GetLast(columns); - Add(&col->rows, window); + Add(&col->rows, it); } } return columns; @@ -23,11 +24,10 @@ Array GetVisualColumns(Allocator allocator) { Window *GetLayoutWindow(int n) { int i = 0; - For(Windows) { - Window *window = it.o; - if (!window->is_column || !window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue; + for (Window *it = FirstWindow; it; it = it->next) { + if (!it->is_column || !it->visible || it->absolute_position || it->is_title_bar || it->is_search_bar) continue; - if (n == i) return window; + if (n == i) return it; i += 1; } return NULL; @@ -35,20 +35,19 @@ Window *GetLayoutWindow(int n) { Window *GetNextLayoutWindow(Window *input_window) { bool found = false; - For(Windows) { - Window *window = it.o; - if (!window->is_column || !window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue; - if (found) return window; - if (window->id == input_window->id) found = true; + for (Window *it = FirstWindow; it; it = it->next) { + if (!it->is_column || !it->visible || it->absolute_position || it->is_title_bar || it->is_search_bar) continue; + if (found) return it; + if (it->id == input_window->id) found = true; } return input_window; } -Array GetWindowZOrder(Allocator allocator) { - Array order = {allocator}; - For(Windows) if (it.o->z == 2) Add(&order, GetIndex(Windows, it)); - For(Windows) if (it.o->z == 1) Add(&order, GetIndex(Windows, it)); - For(Windows) if (it.o->z == 0) Add(&order, GetIndex(Windows, it)); +Array GetWindowZOrder(Allocator allocator) { + Array order = {allocator}; + for (Window *it = FirstWindow; it; it = it->next) if (it->z == 2) Add(&order, it); + for (Window *it = FirstWindow; it; it = it->next) if (it->z == 1) Add(&order, it); + for (Window *it = FirstWindow; it; it = it->next) if (it->z == 0) Add(&order, it); return order; } @@ -115,15 +114,6 @@ void AddColumnWindow() { CreateSearchBar(window->id); } -Int GetWindowIndex(WindowID window_id) { - Int i = 0; - For(Windows) { - if (window_id == it) return i; - i += 1; - } - return 0; -} - void AddRowWindow() { Window *active_window = GetActiveWindow(); Window *window = CreateWindow(); @@ -131,12 +121,6 @@ void AddRowWindow() { window->active_view = view->id; CreateTitlebar(window->id); CreateSearchBar(window->id); - - Int i0 = GetWindowIndex(window->id); - RemoveByIndex(&Windows, i0); - - Int active_window_index = GetWindowIndex(active_window->id); - Insert(&Windows, window->id, active_window_index + 1); } void SetVisibility(WindowID window_id, bool v) { @@ -207,11 +191,6 @@ https://www.lua.org/manual/5.4/ void InitWindows() { Allocator sys_allocator = Perm; -#if !ARRAY_DEBUG - Reserve(&Windows, 64); - Reserve(&Buffers, 256); - Reserve(&Views, 256); -#endif { Window *window = CreateWindow(); @@ -315,23 +294,22 @@ void LayoutWindows(int16_t wx, int16_t wy) { } } - For(Windows) { - Window *window = it.o; - if (!window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue; + for (Window *it = FirstWindow; it; it = it->next) { + if (!it->visible || it->absolute_position || it->is_title_bar || it->is_search_bar) continue; - Window *title_bar_window = GetWindow(window->title_bar_window); - title_bar_window->total_rect = CutBottom(&window->total_rect, GetTitleBarSize(title_bar_window)); + Window *title_bar_window = GetWindow(it->title_bar_window); + title_bar_window->total_rect = CutBottom(&it->total_rect, GetTitleBarSize(title_bar_window)); title_bar_window->document_rect = title_bar_window->total_rect; - Rect2I save_rect = window->document_rect; + Rect2I save_rect = it->document_rect; CutLeft(&save_rect, GetSize(save_rect).x/2); - Window *search_bar_window = GetWindow(window->search_bar_window); + Window *search_bar_window = GetWindow(it->search_bar_window); search_bar_window->total_rect = CutTop(&save_rect, GetTitleBarSize(search_bar_window)); search_bar_window->document_rect = search_bar_window->total_rect; - window->document_rect = window->total_rect; - if (window->draw_scrollbar) window->scrollbar_rect = CutRight(&window->document_rect, (Int)ScrollBarSize); - if (window->draw_line_numbers) window->line_numbers_rect = CutLeft(&window->document_rect, (Int)line_numbers_size); + it->document_rect = it->total_rect; + if (it->draw_scrollbar) it->scrollbar_rect = CutRight(&it->document_rect, (Int)ScrollBarSize); + if (it->draw_line_numbers) it->line_numbers_rect = CutLeft(&it->document_rect, (Int)line_numbers_size); } {