Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 1078:7866dbaf67a6
Use a hash for the list of win buffers
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 04 Dec 2006 22:13:13 +0100 |
parents | c51ca5225516 |
children | 537873e68ea6 |
comparison
equal
deleted
inserted
replaced
1077:c51ca5225516 | 1078:7866dbaf67a6 |
---|---|
50 static unsigned short int Log_Win_Height; | 50 static unsigned short int Log_Win_Height; |
51 static unsigned short int Roster_Width; | 51 static unsigned short int Roster_Width; |
52 | 52 |
53 static inline void check_offset(int); | 53 static inline void check_offset(int); |
54 | 54 |
55 static GSList *winbuflst; | 55 static GHashTable *winbufhash; |
56 | 56 |
57 typedef struct { | 57 typedef struct { |
58 WINDOW *win; | 58 WINDOW *win; |
59 PANEL *panel; | 59 PANEL *panel; |
60 char *name; | 60 char *name; |
62 GList *top; // If top is NULL, we'll display the last lines | 62 GList *top; // If top is NULL, we'll display the last lines |
63 char cleared; // For ex, user has issued a /clear command... | 63 char cleared; // For ex, user has issued a /clear command... |
64 char lock; | 64 char lock; |
65 } winbuf; | 65 } winbuf; |
66 | 66 |
67 struct dimensions { | |
68 int l; | |
69 int c; | |
70 }; | |
67 | 71 |
68 static WINDOW *rosterWnd, *chatWnd, *inputWnd, *logWnd; | 72 static WINDOW *rosterWnd, *chatWnd, *inputWnd, *logWnd; |
69 static WINDOW *mainstatusWnd, *chatstatusWnd; | 73 static WINDOW *mainstatusWnd, *chatstatusWnd; |
70 static PANEL *rosterPanel, *chatPanel, *inputPanel; | 74 static PANEL *rosterPanel, *chatPanel, *inputPanel; |
71 static PANEL *mainstatusPanel, *chatstatusPanel; | 75 static PANEL *mainstatusPanel, *chatstatusPanel; |
451 } | 455 } |
452 update_panels(); | 456 update_panels(); |
453 | 457 |
454 // If title is NULL, this is a special buffer | 458 // If title is NULL, this is a special buffer |
455 if (title) { | 459 if (title) { |
460 char *id; | |
456 // Load buddy history from file (if enabled) | 461 // Load buddy history from file (if enabled) |
457 hlog_read_history(title, &tmp->hbuf, maxX - Roster_Width - PREFIX_WIDTH); | 462 hlog_read_history(title, &tmp->hbuf, maxX - Roster_Width - PREFIX_WIDTH); |
458 | 463 |
459 winbuflst = g_slist_append(winbuflst, tmp); | 464 id = g_strdup(title); |
465 mc_strtolower(id); | |
466 g_hash_table_insert(winbufhash, id, tmp); | |
460 } | 467 } |
461 return tmp; | 468 return tmp; |
462 } | 469 } |
463 | 470 |
464 static winbuf *scr_SearchWindow(const char *winId, int special) | 471 static winbuf *scr_SearchWindow(const char *winId, int special) |
465 { | 472 { |
466 GSList *wblp; | 473 char *id; |
467 winbuf *wbp; | 474 winbuf *wbp; |
468 | 475 |
469 if (special) | 476 if (special) |
470 return statusWindow; // Only one special window atm. | 477 return statusWindow; // Only one special window atm. |
471 | 478 |
472 if (!winId) | 479 if (!winId) |
473 return NULL; | 480 return NULL; |
474 | 481 |
475 for (wblp = winbuflst; wblp; wblp = g_slist_next(wblp)) { | 482 id = g_strdup(winId); |
476 wbp = wblp->data; | 483 mc_strtolower(id); |
477 if (wbp->name) { | 484 wbp = g_hash_table_lookup(winbufhash, id); |
478 if (!strcasecmp(wbp->name, winId)) | 485 g_free(id); |
479 return wbp; | 486 return wbp; |
480 } | |
481 } | |
482 return NULL; | |
483 } | 487 } |
484 | 488 |
485 int scr_BuddyBufferExists(const char *bjid) | 489 int scr_BuddyBufferExists(const char *bjid) |
486 { | 490 { |
487 return (scr_SearchWindow(bjid, FALSE) != NULL); | 491 return (scr_SearchWindow(bjid, FALSE) != NULL); |
831 roster_x_pos = 0; | 835 roster_x_pos = 0; |
832 chat_x_pos = Roster_Width; | 836 chat_x_pos = Roster_Width; |
833 } | 837 } |
834 | 838 |
835 if (fullinit) { | 839 if (fullinit) { |
840 if (!winbufhash) | |
841 winbufhash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
836 /* Create windows */ | 842 /* Create windows */ |
837 rosterWnd = newwin(CHAT_WIN_HEIGHT, Roster_Width, chat_y_pos, roster_x_pos); | 843 rosterWnd = newwin(CHAT_WIN_HEIGHT, Roster_Width, chat_y_pos, roster_x_pos); |
838 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, chat_y_pos, | 844 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, chat_y_pos, |
839 chat_x_pos); | 845 chat_x_pos); |
840 logWnd = newwin(Log_Win_Height-2, maxX, log_y_pos, 0); | 846 logWnd = newwin(Log_Win_Height-2, maxX, log_y_pos, 0); |
924 // We'll need to redraw the roster | 930 // We'll need to redraw the roster |
925 update_roster = TRUE; | 931 update_roster = TRUE; |
926 return; | 932 return; |
927 } | 933 } |
928 | 934 |
929 static inline void resize_win_buffer(winbuf *wbp, int x, int y, | 935 static void resize_win_buffer(gpointer key, gpointer value, gpointer data) |
930 int lines, int cols) | 936 { |
931 { | 937 winbuf *wbp = value; |
938 struct dimensions *dim = data; | |
932 int chat_x_pos, chat_y_pos; | 939 int chat_x_pos, chat_y_pos; |
940 | |
941 if (!(wbp && wbp->win)) | |
942 return; | |
933 | 943 |
934 if (log_win_on_top) | 944 if (log_win_on_top) |
935 chat_y_pos = Log_Win_Height-1; | 945 chat_y_pos = Log_Win_Height-1; |
936 else | 946 else |
937 chat_y_pos = 0; | 947 chat_y_pos = 0; |
940 chat_x_pos = 0; | 950 chat_x_pos = 0; |
941 else | 951 else |
942 chat_x_pos = Roster_Width; | 952 chat_x_pos = Roster_Width; |
943 | 953 |
944 // Resize/move buddy window | 954 // Resize/move buddy window |
945 wresize(wbp->win, lines, cols); | 955 wresize(wbp->win, dim->l, dim->c); |
946 mvwin(wbp->win, chat_y_pos, chat_x_pos); | 956 mvwin(wbp->win, chat_y_pos, chat_x_pos); |
947 werase(wbp->win); | 957 werase(wbp->win); |
948 // If a panel exists, replace the old window with the new | 958 // If a panel exists, replace the old window with the new |
949 if (wbp->panel) | 959 if (wbp->panel) |
950 replace_panel(wbp->panel, wbp->win); | 960 replace_panel(wbp->panel, wbp->win); |
957 // Function called when the window is resized. | 967 // Function called when the window is resized. |
958 // - Resize windows | 968 // - Resize windows |
959 // - Rewrap lines in each buddy buffer | 969 // - Rewrap lines in each buddy buffer |
960 void scr_Resize(void) | 970 void scr_Resize(void) |
961 { | 971 { |
962 int x, y, lines, cols; | 972 struct dimensions dim; |
963 GSList *wblp; | |
964 winbuf *wbp; | |
965 | 973 |
966 // First, update the global variables | 974 // First, update the global variables |
967 getmaxyx(stdscr, maxY, maxX); | 975 getmaxyx(stdscr, maxY, maxX); |
968 // scr_DrawMainWindow() will take care of maxY and Log_Win_Height | 976 // scr_DrawMainWindow() will take care of maxY and Log_Win_Height |
969 | 977 |
972 | 980 |
973 // Resize windows and update panels | 981 // Resize windows and update panels |
974 scr_DrawMainWindow(FALSE); | 982 scr_DrawMainWindow(FALSE); |
975 | 983 |
976 // Resize all buddy windows | 984 // Resize all buddy windows |
977 x = Roster_Width; | 985 dim.l = CHAT_WIN_HEIGHT; |
978 y = 0; | 986 dim.c = maxX - Roster_Width; |
979 lines = CHAT_WIN_HEIGHT; | 987 if (dim.c < 1) |
980 cols = maxX - Roster_Width; | 988 dim.c = 1; |
981 if (cols < 1) cols = 1; | 989 |
982 | 990 // Resize all buffers |
983 for (wblp = winbuflst; wblp; wblp = g_slist_next(wblp)) { | 991 g_hash_table_foreach(winbufhash, resize_win_buffer, &dim); |
984 wbp = wblp->data; | |
985 if (wbp->win) | |
986 resize_win_buffer(wbp, x, y, lines, cols); | |
987 } | |
988 | 992 |
989 // Resize/move special status buffer | 993 // Resize/move special status buffer |
990 if (statusWindow) | 994 if (statusWindow) |
991 resize_win_buffer(statusWindow, x, y, lines, cols); | 995 resize_win_buffer(NULL, statusWindow, &dim); |
992 | 996 |
993 // Refresh current buddy window | 997 // Refresh current buddy window |
994 if (chatmode) | 998 if (chatmode) |
995 scr_ShowBuddyWindow(); | 999 scr_ShowBuddyWindow(); |
996 } | 1000 } |