Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 151:b69c0b7a23e3
[/trunk] Changeset 163 by mikael
* Window resize handling 8-)
author | mikael |
---|---|
date | Sun, 01 May 2005 03:14:19 +0000 |
parents | 9f74832eb4f8 |
children | ae0844311710 |
comparison
equal
deleted
inserted
replaced
150:5647381a7dfb | 151:b69c0b7a23e3 |
---|---|
15 #include "parsecfg.h" | 15 #include "parsecfg.h" |
16 #include "utils.h" | 16 #include "utils.h" |
17 #include "list.h" | 17 #include "list.h" |
18 | 18 |
19 #define window_entry(n) list_entry(n, window_entry_t, list) | 19 #define window_entry(n) list_entry(n, window_entry_t, list) |
20 | |
21 inline void check_offset(int); | |
20 | 22 |
21 LIST_HEAD(window_list); | 23 LIST_HEAD(window_list); |
22 | 24 |
23 typedef struct _window_entry_t { | 25 typedef struct _window_entry_t { |
24 WINDOW *win; | 26 WINDOW *win; |
174 i++; | 176 i++; |
175 } | 177 } |
176 } | 178 } |
177 | 179 |
178 | 180 |
179 window_entry_t *scr_CreatePanel(const char *title, int x, int y, | 181 window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) |
180 int lines, int cols, int dont_show) | 182 { |
181 { | 183 int x; |
184 int y; | |
185 int lines; | |
186 int cols; | |
182 window_entry_t *tmp = calloc(1, sizeof(window_entry_t)); | 187 window_entry_t *tmp = calloc(1, sizeof(window_entry_t)); |
188 | |
189 // Dimensions | |
190 x = ROSTER_WIDTH; | |
191 y = 0; | |
192 lines = CHAT_WIN_HEIGHT; | |
193 cols = maxX - ROSTER_WIDTH; | |
183 | 194 |
184 tmp->win = newwin(lines, cols, y, x); | 195 tmp->win = newwin(lines, cols, y, x); |
185 tmp->panel = new_panel(tmp->win); | 196 tmp->panel = new_panel(tmp->win); |
186 tmp->name = (char *) calloc(1, 1024); | 197 tmp->name = (char *) calloc(1, 1024); |
187 strncpy(tmp->name, title, 1024); | 198 strncpy(tmp->name, title, 1024); |
363 else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry)))) | 374 else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry)))) |
364 dont_show = TRUE; | 375 dont_show = TRUE; |
365 | 376 |
366 // If the window entry doesn't exist yet, let's create it. | 377 // If the window entry doesn't exist yet, let's create it. |
367 if (win_entry == NULL) { | 378 if (win_entry == NULL) { |
368 win_entry = scr_CreatePanel(winId, ROSTER_WIDTH, 0, CHAT_WIN_HEIGHT, | 379 win_entry = scr_CreateBuddyPanel(winId, dont_show); |
369 maxX - ROSTER_WIDTH, dont_show); | |
370 } | 380 } |
371 | 381 |
372 hbuf_add_line(&win_entry->hbuf, text, fullprefix, | 382 hbuf_add_line(&win_entry->hbuf, text, fullprefix, |
373 maxX - scr_WindowWidth(rosterWnd) - 14); | 383 maxX - scr_WindowWidth(rosterWnd) - 14); |
374 free(fullprefix); | 384 free(fullprefix); |
417 refresh(); | 427 refresh(); |
418 endwin(); | 428 endwin(); |
419 return; | 429 return; |
420 } | 430 } |
421 | 431 |
422 void scr_DrawMainWindow(void) | 432 // scr_DrawMainWindow() |
433 // Set fullinit to TRUE to also create panels | |
434 // | |
435 // I think it could be improved a _lot_ but I'm really not an ncurses | |
436 // expert... :-\ Mikael. | |
437 // | |
438 void scr_DrawMainWindow(unsigned int fullinit) | |
423 { | 439 { |
424 int l; | 440 int l; |
425 | 441 |
426 /* Draw main panels */ | 442 /* Create windows */ |
427 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); | 443 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); |
428 rosterPanel = new_panel(rosterWnd); | 444 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); |
445 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); | |
446 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1); | |
447 inputWnd = newwin(1, maxX, maxY-1, 0); | |
448 | |
449 /* Draw/init windows */ | |
450 | |
451 // - Clear roster and draw vertical line | |
429 scr_clear_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, ROSTER_WIDTH, | 452 scr_clear_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, ROSTER_WIDTH, |
430 COLOR_GENERAL); | 453 COLOR_GENERAL); |
431 for (l=0 ; l < CHAT_WIN_HEIGHT ; l++) | 454 for (l=0 ; l < CHAT_WIN_HEIGHT ; l++) |
432 mvwaddch(rosterWnd, l, ROSTER_WIDTH-1, ACS_VLINE); | 455 mvwaddch(rosterWnd, l, ROSTER_WIDTH-1, ACS_VLINE); |
433 | 456 |
434 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); | 457 // - Clear chat window |
435 chatPanel = new_panel(chatWnd); | |
436 scr_clear_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, | 458 scr_clear_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, |
437 COLOR_GENERAL); | 459 COLOR_GENERAL); |
438 scrollok(chatWnd, TRUE); | |
439 mvwprintw(chatWnd, 0, 0, "This is the status window"); | 460 mvwprintw(chatWnd, 0, 0, "This is the status window"); |
440 | 461 |
441 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); | 462 // - Draw/clear the log window |
442 logPanel_border = new_panel(logWnd_border); | |
443 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); | 463 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); |
444 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1); | |
445 logPanel = new_panel(logWnd); | |
446 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); | 464 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
447 | |
448 scrollok(logWnd, TRUE); | 465 scrollok(logWnd, TRUE); |
449 | 466 |
450 inputWnd = newwin(1, maxX, maxY-1, 0); | 467 // Enable keypad (+ special keys) |
451 inputPanel = new_panel(inputWnd); | 468 keypad(inputWnd, TRUE); |
452 | 469 |
470 if (fullinit) { | |
471 // Create panels | |
472 rosterPanel = new_panel(rosterWnd); | |
473 chatPanel = new_panel(chatWnd); | |
474 logPanel_border = new_panel(logWnd_border); | |
475 logPanel = new_panel(logWnd); | |
476 inputPanel = new_panel(inputWnd); | |
477 } | |
478 | |
479 // We'll need to redraw the roster | |
453 update_roster = TRUE; | 480 update_roster = TRUE; |
454 return; | 481 return; |
482 } | |
483 | |
484 // scr_Resize() | |
485 // Function called when the window is resized. | |
486 // - Recreate windows | |
487 // - Update panels | |
488 // - Rewrap lines in each buddy buffer | |
489 void scr_Resize() | |
490 { | |
491 WINDOW *w_roster, *w_chat, *w_log, *w_log_bord, *w_input; | |
492 | |
493 struct list_head *pos, *n; | |
494 window_entry_t *search_entry; | |
495 int x, y, lines, cols; | |
496 | |
497 // First, update the global variables | |
498 getmaxyx(stdscr, maxY, maxX); | |
499 // Make sure the cursor stays inside the window | |
500 check_offset(0); | |
501 | |
502 // Backup pointers | |
503 w_roster = rosterWnd; | |
504 w_chat = chatWnd; | |
505 w_log = logWnd; | |
506 w_log_bord = logWnd_border; | |
507 w_input = inputWnd; | |
508 | |
509 // Recreate windows | |
510 scr_DrawMainWindow(FALSE); | |
511 | |
512 // Replace windows for panels | |
513 replace_panel(rosterPanel, rosterWnd); | |
514 replace_panel(chatPanel, chatWnd); | |
515 replace_panel(logPanel, logWnd); | |
516 replace_panel(logPanel_border, logWnd_border); | |
517 replace_panel(inputPanel, inputWnd); | |
518 | |
519 // Destroy old windows | |
520 delwin(w_roster); | |
521 delwin(w_chat); | |
522 delwin(w_log); | |
523 delwin(w_log_bord); | |
524 delwin(w_input); | |
525 | |
526 // Resize all buddy windows | |
527 x = ROSTER_WIDTH; | |
528 y = 0; | |
529 lines = CHAT_WIN_HEIGHT; | |
530 cols = maxX - ROSTER_WIDTH; | |
531 | |
532 list_for_each_safe(pos, n, &window_list) { | |
533 search_entry = window_entry(pos); | |
534 if (search_entry->win) { | |
535 WINDOW *w_buddy = search_entry->win; | |
536 // Create new window | |
537 search_entry->win = newwin(lines, cols, y, x); | |
538 scr_clear_box(search_entry->win, 0, 0, lines, cols, COLOR_GENERAL); | |
539 // If a panel exists, replace the old window with the new | |
540 if (search_entry->panel) { | |
541 replace_panel(search_entry->panel, search_entry->win); | |
542 } | |
543 // Redo line wrapping | |
544 hbuf_rebuild(&search_entry->hbuf, | |
545 maxX - scr_WindowWidth(rosterWnd) - 14); | |
546 // Delete old buddy window | |
547 delwin(w_buddy); | |
548 } | |
549 } | |
550 | |
551 // Refresh current buddy window | |
552 if (chatmode) | |
553 scr_ShowBuddyWindow(); | |
455 } | 554 } |
456 | 555 |
457 // scr_DrawRoster() | 556 // scr_DrawRoster() |
458 // Actually, display the buddylist on the screen. | 557 // Actually, display the buddylist on the screen. |
459 void scr_DrawRoster(void) | 558 void scr_DrawRoster(void) |
1102 if (current_buddy) | 1201 if (current_buddy) |
1103 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | 1202 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
1104 top_panel(chatPanel); | 1203 top_panel(chatPanel); |
1105 top_panel(inputPanel); | 1204 top_panel(inputPanel); |
1106 break; | 1205 break; |
1206 case 12: // Ctrl-l | |
1207 case KEY_RESIZE: | |
1208 scr_Resize(); | |
1209 break; | |
1107 default: | 1210 default: |
1108 scr_LogPrint("Unkown key=%d", key); | 1211 scr_LogPrint("Unkown key=%d", key); |
1109 } | 1212 } |
1110 } | 1213 } |
1111 if (completion_started && key != 9) | 1214 if (completion_started && key != 9) |