comparison mcabber/src/screen.c @ 44:c10f95f959d0

[/trunk] Changeset 60 by mikael * screen.c cleanup * Remove scr_CreatePopup() * Improve message splitting, to use full window width.
author mikael
date Tue, 05 Apr 2005 21:15:49 +0000
parents 82247685b14b
children 7259a61e1a4b
comparison
equal deleted inserted replaced
43:b8bd163be431 44:c10f95f959d0
187 update_panels(); 187 update_panels();
188 188
189 return tmp; 189 return tmp;
190 } 190 }
191 191
192
193 void scr_CreatePopup(char *title, char *texto, int corte, int type,
194 char *returnstring)
195 {
196 WINDOW *popupWin;
197 PANEL *popupPanel;
198
199 int lineas = 0;
200 int cols = 0;
201
202 char **submsgs;
203 int n = 0;
204 int i;
205
206 char *instr = (char *) calloc(1, 1024);
207
208 /* fprintf(stderr, "\r\n%d", lineas); */
209
210 submsgs = ut_SplitMessage(texto, &n, corte);
211
212 switch (type) {
213 case 1:
214 case 0:
215 lineas = n + 4;
216 break;
217 }
218
219 cols = corte + 3;
220 popupWin = newwin(lineas, cols, (maxY - lineas) / 2, (maxX - cols) / 2);
221 popupPanel = new_panel(popupWin);
222
223 /*ATENCION!!! Colorear el popup ??
224 / box (popupWin, 0, 0); */
225 scr_draw_box(popupWin, 0, 0, lineas, cols, COLOR_POPUP, 0, 0);
226 mvwprintw(popupWin, 0, (cols - (2 + strlen(title))) / 2, " %s ", title);
227
228 for (i = 0; i < n; i++)
229 mvwprintw(popupWin, i + 1, 2, "%s", submsgs[i]);
230
231
232 for (i = 0; i < n; i++)
233 free(submsgs[i]);
234 free(submsgs);
235
236 switch (type) {
237 case 0:
238 mvwprintw(popupWin, n + 2,
239 (cols - (2 + strlen(i18n("Press any key")))) / 2,
240 i18n("Press any key"));
241 update_panels();
242 doupdate();
243 getch();
244 break;
245 case 1:
246 {
247 char ch;
248 int scroll = 0;
249 int input_x = 0;
250
251 wmove(popupWin, 3, 1);
252 wrefresh(popupWin);
253 keypad(popupWin, TRUE);
254 while ((ch = getch()) != '\n') {
255 switch (ch) {
256 case 0x09:
257 case KEY_UP:
258 case KEY_DOWN:
259 break;
260 case KEY_RIGHT:
261 case KEY_LEFT:
262 break;
263 case KEY_BACKSPACE:
264 case 127:
265 if (input_x || scroll) {
266 /* wattrset (popupWin, 0); */
267 if (!input_x) {
268 scroll = scroll < cols - 3 ? 0 : scroll - (cols - 3);
269 wmove(popupWin, 3, 1);
270 for (i = 0; i < cols; i++)
271 waddch
272 (popupWin,
273 instr
274 [scroll
275 + input_x + i] ? instr[scroll + input_x + i] : ' ');
276 input_x = strlen(instr) - scroll;
277 } else
278 input_x--;
279 instr[scroll + input_x] = '\0';
280 mvwaddch(popupWin, 3, input_x + 1, ' ');
281 wmove(popupWin, 3, input_x + 1);
282 wrefresh(popupWin);
283 }
284 default:
285 if ( /*ch<0x100 && */ isprint(ch) || ch == 'ñ'
286 || ch == 'Ñ') {
287 if (scroll + input_x < 1024) {
288 instr[scroll + input_x] = ch;
289 instr[scroll + input_x + 1] = '\0';
290 if (input_x == cols - 3) {
291 scroll++;
292 wmove(popupWin, 3, 1);
293 for (i = 0; i < cols - 3; i++)
294 waddch(popupWin, instr[scroll + i]);
295 } else {
296 wmove(popupWin, 3, 1 + input_x++);
297 waddch(popupWin, ch);
298 }
299 wrefresh(popupWin);
300 } else {
301 flash();
302 }
303 }
304 }
305 }
306 }
307 if (returnstring != NULL)
308 strcpy(returnstring, instr);
309 break;
310 }
311
312 del_panel(popupPanel);
313 delwin(popupWin);
314 update_panels();
315 doupdate();
316 free(instr);
317 keypad(inputWnd, TRUE);
318 }
319
320 void scr_RoolWindow(void) 192 void scr_RoolWindow(void)
321 { 193 {
322 } 194 }
323 195
324 window_entry_t *scr_SearchWindow(char *winId) 196 window_entry_t *scr_SearchWindow(char *winId)
379 int i; 251 int i;
380 int width; 252 int width;
381 window_entry_t *tmp; 253 window_entry_t *tmp;
382 int dont_show = FALSE; 254 int dont_show = FALSE;
383 255
384
385 tmp = scr_SearchWindow(winId); 256 tmp = scr_SearchWindow(winId);
386 257
387 if (!chatmode) 258 if (!chatmode)
388 dont_show = TRUE; 259 dont_show = TRUE;
389 else if ((!force_show) && ((!currentWindow || (currentWindow != tmp)))) 260 else if ((!force_show) && ((!currentWindow || (currentWindow != tmp))))
390 dont_show = TRUE; 261 dont_show = TRUE;
391 // scr_LogPrint("dont_show=%d", dont_show);
392 262
393 if (tmp == NULL) { 263 if (tmp == NULL) {
394 tmp = scr_CreatePanel(winId, ROSTER_WEIGHT, 0, CHAT_WIN_HEIGHT, 264 tmp = scr_CreatePanel(winId, ROSTER_WEIGHT, 0, CHAT_WIN_HEIGHT,
395 maxX - ROSTER_WEIGHT, dont_show); 265 maxX - ROSTER_WEIGHT, dont_show);
396 tmp->texto = (char **) calloc((CHAT_WIN_HEIGHT+1) * 3, sizeof(char *)); 266 tmp->texto = (char **) calloc((CHAT_WIN_HEIGHT+1) * 3, sizeof(char *));
474 void scr_DrawMainWindow(void) 344 void scr_DrawMainWindow(void)
475 { 345 {
476 /* Draw main panels */ 346 /* Draw main panels */
477 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WEIGHT, 0, 0); 347 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WEIGHT, 0, 0);
478 rosterPanel = new_panel(rosterWnd); 348 rosterPanel = new_panel(rosterWnd);
479 scr_draw_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, ROSTER_WEIGHT, COLOR_GENERAL, 0, 0); 349 scr_draw_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, ROSTER_WEIGHT,
350 COLOR_GENERAL, 0, 0);
480 mvwprintw(rosterWnd, 0, (ROSTER_WEIGHT - strlen(i18n("Roster"))) / 2, 351 mvwprintw(rosterWnd, 0, (ROSTER_WEIGHT - strlen(i18n("Roster"))) / 2,
481 i18n("Roster")); 352 i18n("Roster"));
482 353
483 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WEIGHT, 0, ROSTER_WEIGHT); 354 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WEIGHT, 0, ROSTER_WEIGHT);
484 chatPanel = new_panel(chatWnd); 355 chatPanel = new_panel(chatWnd);
485 scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - ROSTER_WEIGHT, COLOR_GENERAL, 0, 0); 356 scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - ROSTER_WEIGHT,
486 //mvwprintw(chatWnd, 0, 357 COLOR_GENERAL, 0, 0);
487 // ((maxX - 20) - strlen(i18n("Status Window"))) / 2,
488 // i18n("Status Window"));
489 //wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
490 mvwprintw(chatWnd, 1, 1, "This is the status window"); 358 mvwprintw(chatWnd, 1, 1, "This is the status window");
491 359
492 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); 360 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0);
493 logPanel_border = new_panel(logWnd_border); 361 logPanel_border = new_panel(logWnd_border);
494 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); 362 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0);
495 // mvwprintw(logWnd_border, 0,
496 // ((maxX - 20) - strlen(i18n("Log Window"))) / 2,
497 // i18n("Log Window"));
498 //logWnd = newwin(LOG_WIN_HEIGHT - 2, maxX-20 - 2, CHAT_WIN_HEIGHT+1, 20+1);
499 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1); 363 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1);
500 logPanel = new_panel(logWnd); 364 logPanel = new_panel(logWnd);
501 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); 365 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
502 //wattrset(logWnd, COLOR_PAIR(COLOR_GENERAL));
503 366
504 scrollok(logWnd,TRUE); 367 scrollok(logWnd,TRUE);
505 //idlok(logWnd,TRUE); // XXX Necessary?
506 368
507 inputWnd = newwin(1, maxX, maxY-1, 0); 369 inputWnd = newwin(1, maxX, maxY-1, 0);
508 inputPanel = new_panel(inputWnd); 370 inputPanel = new_panel(inputWnd);
509 //wbkgd(inputWnd, COLOR_PAIR(COLOR_GENERAL));
510 371
511 bud_DrawRoster(rosterWnd); 372 bud_DrawRoster(rosterWnd);
512 update_panels(); 373 update_panels();
513 doupdate(); 374 doupdate();
514 return; 375 return;
529 char *buffer = (char *) malloc(5 + strlen(text)); 390 char *buffer = (char *) malloc(5 + strlen(text));
530 391
531 sprintf(buffer, "<== %s", utf8_decode(text)); 392 sprintf(buffer, "<== %s", utf8_decode(text));
532 393
533 submsgs = 394 submsgs =
534 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - ROSTER_WEIGHT); 395 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 14);
535 396
536 for (i = 0; i < n; i++) { 397 for (i = 0; i < n; i++) {
537 if (i == 0) 398 if (i == 0)
538 scr_WriteInWindow(jidfrom, submsgs[i], TRUE, FALSE); 399 scr_WriteInWindow(jidfrom, submsgs[i], TRUE, FALSE);
539 else 400 else
573 WINDOW *scr_GetInputWindow(void) 434 WINDOW *scr_GetInputWindow(void)
574 { 435 {
575 return inputWnd; 436 return inputWnd;
576 } 437 }
577 438
439 // scr_LogPrint(...)
440 // Display a message in the log window.
578 void scr_LogPrint(const char *fmt, ...) 441 void scr_LogPrint(const char *fmt, ...)
579 { 442 {
580 time_t timestamp; 443 time_t timestamp;
581 char *buffer; 444 char *buffer;
582 va_list ap; 445 va_list ap;
609 return TRUE; 472 return TRUE;
610 473
611 return FALSE; 474 return FALSE;
612 } 475 }
613 476
477 // send_message(msg)
478 // Write the message in the buddy's window and send the message on
479 // the network.
614 void send_message(char *msg) 480 void send_message(char *msg)
615 { 481 {
616 char **submsgs; 482 char **submsgs;
617 char *buffer = (char *) calloc(1, 24+strlen(msg)); 483 char *buffer = (char *) calloc(1, 24+strlen(msg));
618 char *buffer2 = (char *) calloc(1, 1024); 484 char *buffer2 = (char *) calloc(1, 1024);
623 489
624 sprintf(buffer, "--> %s", msg); 490 sprintf(buffer, "--> %s", msg);
625 491
626 submsgs = 492 submsgs =
627 ut_SplitMessage(buffer, &n, 493 ut_SplitMessage(buffer, &n,
628 maxX - scr_WindowHeight(rosterWnd) - ROSTER_WEIGHT); 494 maxX - scr_WindowHeight(rosterWnd) - 14);
629 for (i = 0; i < n; i++) { 495 for (i = 0; i < n; i++) {
630 if (i == 0) 496 if (i == 0)
631 scr_WriteInWindow(tmp->jid, submsgs[i], TRUE, TRUE); 497 scr_WriteInWindow(tmp->jid, submsgs[i], TRUE, TRUE);
632 else 498 else
633 scr_WriteInWindow(tmp->jid, submsgs[i], FALSE, TRUE); 499 scr_WriteInWindow(tmp->jid, submsgs[i], FALSE, TRUE);
635 501
636 for (i = 0; i < n; i++) 502 for (i = 0; i < n; i++)
637 free(submsgs[i]); 503 free(submsgs[i]);
638 free(submsgs); 504 free(submsgs);
639 505
640 //move(CHAT_WIN_HEIGHT - 1, maxX - 1);
641 refresh(); 506 refresh();
642 sprintf(buffer2, "%s@%s/%s", cfg_read("username"), 507 sprintf(buffer2, "%s@%s/%s", cfg_read("username"),
643 cfg_read("server"), cfg_read("resource")); 508 cfg_read("server"), cfg_read("resource"));
644 jb_send_msg(tmp->jid, utf8_encode(msg)); 509 jb_send_msg(tmp->jid, utf8_encode(msg));
645 free(buffer); 510 free(buffer);
646 free(buffer2); 511 free(buffer2);
647 512
648 top_panel(inputPanel); 513 top_panel(inputPanel);
649 } 514 }
650 515
516 // process_line(line)
517 // Process the line *line. Note: if this isn't a command, this is a message
518 // and it is sent to the current buddy.
651 int process_line(char *line) 519 int process_line(char *line)
652 { 520 {
653 if (*line != '/') { 521 if (*line != '/') {
654 send_message(line); 522 send_message(line);
655 return 0; 523 return 0;
685 while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX) 553 while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX)
686 inputline_offset += 5; 554 inputline_offset += 5;
687 } 555 }
688 } 556 }
689 557
558 // process_key(key)
559 // Handle the pressed key, in the command line (bottom).
690 int process_key(int key) 560 int process_key(int key)
691 { 561 {
692 if (isprint(key)) { 562 if (isprint(key)) {
693 char tmpLine[INPUTLINE_LENGTH+1]; 563 char tmpLine[INPUTLINE_LENGTH+1];
694 564
728 break; 598 break;
729 case 9: // Tab 599 case 9: // Tab
730 scr_LogPrint("I'm unable to complete yet"); 600 scr_LogPrint("I'm unable to complete yet");
731 break; 601 break;
732 case '\n': // Enter 602 case '\n': // Enter
733 // XXX Test:
734 chatmode = TRUE; 603 chatmode = TRUE;
735 if (inputLine[0] == 0) { 604 if (inputLine[0] == 0) {
736 scr_ShowBuddyWindow(); 605 scr_ShowBuddyWindow();
737 break; 606 break;
738 } 607 }
790 top_panel(inputPanel); 659 top_panel(inputPanel);
791 break; 660 break;
792 default: 661 default:
793 scr_LogPrint("Unkown key=%d", key); 662 scr_LogPrint("Unkown key=%d", key);
794 } 663 }
795 //scr_LogPrint("[%02x]", key);
796 } 664 }
797 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); 665 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset);
798 wclrtoeol(inputWnd); 666 wclrtoeol(inputWnd);
799 if (*ptr_inputline) { 667 if (*ptr_inputline) {
800 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset); 668 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset);