void followup(player *p,char *str) { char *oldstack,*body,*indent,*scan,*first; note *article,*old; oldstack=stack; old=find_news_article(atoi(str)); if (!old) { sprintf(stack,"No such news article '%s'\n",str); stack=end_string(stack); tell_player(p,oldstack); stack=oldstack; return; } article=create_note(); if (strstr(old->header,"Re: ")==old->header) strcpy(article->header,old->header); else { sprintf(stack,"Re: %s",old->header); strncpy(article->header,stack,MAX_TITLE-2); } article->flags |= NEWS_ARTICLE; first=first_char(p); scan=strstr(first,"followup"); if (scan && (scan!=first_char(p)) && (*(scan-1)=='a')) article->flags |= ANONYMOUS; strcpy(article->name,p->name); indent=stack; get_string(stack,old->text.where); stack=end_string(stack); body=stack; if (old->flags&ANONYMOUS) sprintf(stack,"From annonymous article written on %s ...\n", convert_time(old->date)); else sprintf(stack,"On %s, %s wrote ...\n", convert_time(old->date),old->name); stack=strchr(stack,0); while(*indent) { *stack++='>'; *stack++=' '; while(*indent && *indent!='\n') *stack++=*indent++; *stack++='\n'; indent++; } *stack++='\n'; *stack++=0; tell_player(p,"Please trim article as much as is possible ....\n"); start_edit(p,MAX_ARTICLE_SIZE,end_post,quit_post,body); if (p->edit_info) p->edit_info->misc=(void *)article; else FREE(article); stack=oldstack; }
wm_lbuttondblclk(TableUI *tui, unsigned x, unsigned y) { unsigned row, col, is_resize; exit_mouse_mode(tui); get_cell_under(tui, x, y, &row, &col, &is_resize); if (is_resize) auto_resize_col(tui, col); else { command(tui, IsShiftDown()? CmdSetAnchor: CmdClearAnchor); jump_cursor(tui, row, col); command(tui, CmdEditCell); start_edit(tui, 1); } }
void main_screen(void) { int c, quit = 0; char file[70]; size_t filelen = 0; file[0] = 0; while(!quit) { clear_screen(); cursor_on(); cursor(30, 1); printf("TMAZE by DWK"); cursor(5, 20); printf("%s", file); switch((c=getch())) { case 0: /* extended key */ switch((c=getch())) { /*case 72: /* up */ } /*cursor(0, 1); printf("%3i", c);*/ break; case 27: quit = 1; break; /* esc */ case '\b': if(filelen > 0) { file[--filelen] = 0; } break; case '\r': start_game(file); break; case 10: /* ctrl-enter */ start_edit(file); break; default: if(isprint(c) && filelen < 70) { file[filelen++] = c; file[filelen] = 0; } } } }
void send_letter(player *p,char *str) { note *mail; char *subject,*scan,*first; int length; if (posted_count(p)>=p->max_mail) { tell_player(p,"Sorry, you have reached your mail limit.\n"); return; } subject=next_space(str); if (!*subject) { tell_player(p,"Format: post <character(s)> <subject>\n"); return; } *subject++=0; mail=create_note(); first=first_char(p); scan=strstr(first,"post"); if (scan && (scan!=first_char(p)) && (*(scan-1)=='a')) mail->flags |= ANONYMOUS; strcpy(mail->name,p->name); strncpy(mail->header,subject,MAX_TITLE-2); tell_player(p,"Enter main text of the letter...\n"); *stack=0; start_edit(p,MAX_ARTICLE_SIZE,end_mail,quit_mail,stack); if (p->edit_info) { p->edit_info->misc=(void *)mail; length=strlen(str)+1; mail->text.where=(char *)MALLOC(length); memcpy(mail->text.where,str,length); } else FREE(mail); }
void post_news(player *p,char *str) { note *article; char *scan,*first; if (!*str) { tell_player(p,"Format: post <header>\n"); return; } article=create_note(); strncpy(article->header,str,MAX_TITLE-2); article->flags |= NEWS_ARTICLE; first=first_char(p); scan=strstr(first,"post"); if (scan && (scan!=first_char(p)) && (*(scan-1)=='a')) article->flags |= ANONYMOUS; strcpy(article->name,p->name); tell_player(p,"Now enter the main body text for the article.\n"); *stack=0; start_edit(p,MAX_ARTICLE_SIZE,end_post,quit_post,stack); if (p->edit_info) p->edit_info->misc=(void *)article; else FREE(article); }
void reply_article(player *p,char *str) { note *mail,*old; char *indent,*body,*oldstack,*scan,*first; int length; oldstack=stack; if (!*str) { tell_player(p,"Format: reply <no>\n"); return; } if (posted_count(p)>=p->max_mail) { tell_player(p,"Sorry, you have reached your mail limit.\n"); return; } if (!p->saved) { tell_player(p,"Eeek, no saved bits.\n"); return; } old=find_news_article(atoi(str)); if (!old) { sprintf(stack,"Can't find letter '%s'\n",str); stack=end_string(stack); tell_player(p,oldstack); stack=oldstack; return; } mail=create_note(); first=first_char(p); scan=strstr(first,"reply"); if (scan && (scan!=first_char(p)) && (*(scan-1)=='a')) mail->flags |= ANONYMOUS; if (old->flags&ANONYMOUS) mail->flags |= SUPRESS_NAME; strcpy(mail->name,p->name); if (strstr(old->header,"Re: ")==old->header) strcpy(mail->header,old->header); else { sprintf(stack,"Re: %s",old->header); strncpy(mail->header,stack,MAX_TITLE-2); } indent=stack; get_string(stack,old->text.where); stack=end_string(stack); body=stack; sprintf(stack,"In your article '%s' you wrote ...\n",old->header); stack=strchr(stack,0); while(*indent) { *stack++='>'; *stack++=' '; while(*indent && *indent!='\n') *stack++=*indent++; *stack++='\n'; indent++; } *stack++='\n'; *stack++=0; tell_player(p,"Please trim letter as much as possible...\n"); start_edit(p,MAX_ARTICLE_SIZE,end_mail,quit_mail,body); if (p->edit_info) { p->edit_info->misc=(void *)mail; length=strlen(old->name)+1; mail->text.where=(char *)MALLOC(length); memcpy(mail->text.where,old->name,length); } else FREE(mail); stack=oldstack; }
void process_key() { Dword mouse_btn, ckeys, shift, ctrl; int mouse_x, mouse_y, dx = 0, dy = 0; // key pressed, read it Byte keyCode; ckeys = kos_GetSpecialKeyState(); shift = ckeys & 0x3; ctrl = ckeys & 0x0c; //if (ctrl) // rtlDebugOutString("control pressed!"); dx = 0, dy = 0; sel_moved = 0; sel_end_move = 0; kos_GetKey(keyCode); __asm { mov ah, keyCode } edit_box_key((dword)&cell_box); edit_box_key((dword)&file_box); switch (keyCode) { case 178: // стрелки //dx = 0; dy = -1; break; case 176: dx = -1; //dy = 0; break; case 179: dx = 1; //dy = 0; break; case 177: //dx = 0; dy = 1; break; /* case 183: if (sel_y < row_count-(ny - scroll_y)) // page down dy = ny - scroll_y; else dy = row_count-(ny - scroll_y) - sel_y; dx = 0; redraw = 1; break; case 184: if (sel_y > ny - scroll_y) // page up dy= - (ny - scroll_y); else dy = - (ny - scroll_y) + sel_y; dx = 0; redraw = 1; break; */ case 180: //home dx = -sel_x + 1; dy = 0; draw_grid(); //draw_window(); break; case 181: //end dx = col_count - (nx - scroll_x) - 1 - sel_x; dy = 0; draw_grid(); //draw_window(); break; case 27: // escape cancel_edit(); break; case 182: // delete { int i,j,n0,n1,k0,k1; n0 = min(sel_x, sel_end_x); n1 = max(sel_x, sel_end_x); k0 = min(sel_y, sel_end_y); k1 = max(sel_y, sel_end_y); for (i = n0; i <= n1; i++) for (j = k0; j <= k1; j++) { if (cells[i][j]) { freemem(cells[i][j]); cells[i][j] = NULL; } } calculate_values(); draw_grid(); break; } case 0x0D: // enter if (is_edit) { stop_edit(); draw_window(); } break; case 22: // contol-v { if (ctrl) { //rtlDebugOutString("control-v!"); int i, j, x0, y0; x0 = min(sel_x, sel_end_x); y0 = min(sel_y, sel_end_y); int delta_x = x0 - buf_old_x; int delta_y = y0 - buf_old_y; for (i = 0; i < buf_col; i++) for (j = 0; j < buf_row; j++) { if (i + x0 >= col_count || j + y0 >= row_count) continue; if (cells[i + x0][j + y0]) freemem(cells[i + x0][j + y0]); if (buffer[i][j]) { cf_x0 = buf_old_x; cf_y0 = buf_old_y; cf_x1 = buf_old_x + buf_col; cf_y1 = buf_old_y + buf_row; cells[i + x0][j + y0] = change_formula(buffer[i][j], delta_x, delta_y); //cells[i + x0][j + y0] = (char*)allocmem(strlen(buffer[i][j])); //strcpy(cells[i + x0][j + y0], buffer[i][j]); } else cells[i + x0][j + y0] = NULL; } calculate_values(); draw_window(); break; } } case 24: // control-x case 03: // control-c { if (ctrl) { //rtlDebugOutString("control-c!"); int i, j, x0, y0; freeBuffer(); buf_col = abs(sel_end_x - sel_x) + 1; buf_row = abs(sel_end_y - sel_y) + 1; x0 = min(sel_x, sel_end_x); y0 = min(sel_y, sel_end_y); buf_old_x = x0; buf_old_y = y0; //sprintf(debuf, "%U %U %U %U", buf_col, buf_row, x0, y0); //rtlDebugOutString(debuf); buffer = (char***)allocmem(buf_col * sizeof(char**)); for (i = 0; i < buf_col; i++) { buffer[i] = (char**)allocmem(buf_row * sizeof(char*)); for (j = 0; j < buf_row; j++) { if (cells[i + x0][j + y0]) { if (keyCode == 03) // ctrl-c { buffer[i][j] = (char*)allocmem(strlen(cells[i + x0][j + y0])); strcpy(buffer[i][j], cells[i + x0][j + y0]); } else { buffer[i][j] = cells[i + x0][j + y0]; cells[i + x0][j + y0] = NULL; } } else buffer[i][j] = NULL; } } if (keyCode == 24) calculate_values(); draw_window(); break; } } case 06: // control-f { display_formulas = !display_formulas; draw_grid(); //draw_window(); break; } default: if (!is_edit && !(file_box.flags & ed_focus)) { start_edit(sel_x, sel_y); if (keyCode == 8) { cell_box.pos = strlen(edit_text); } else { __asm { mov ah, keyCode } edit_box_key((dword)&cell_box); } } if (is_edit) edit_box_draw((dword)&cell_box); break; } if (dx != 0) { if (shift) { sel_end_x += dx; if (sel_end_x <= 1) sel_end_x = 1; else if (sel_end_x >= col_count) sel_end_x = col_count - 1; // sprintf(debuf,"sel end x change. sel end %U %U",sel_end_x,sel_end_y); // rtlDebugOutString(debuf); sel_moved = sel_end_move = 1; //stop_edit(); //draw_grid(); } else { } } if (dy != 0) { if (shift) { sel_end_y += dy; if (sel_end_y <= 1) sel_end_y = 1; else if (sel_end_y >= row_count) sel_end_y = row_count - 1; // sprintf(debuf,"sel end y change. sel end %U %U",sel_end_x,sel_end_y); // rtlDebugOutString(debuf); sel_moved = sel_end_move = 1; //stop_edit(); //draw_grid(); } } /* if (sel_end_x < sel_x) { Dword tmp = sel_end_x; sel_end_x = sel_x; sel_x = tmp; } if (sel_end_y < sel_y) { Dword tmp = sel_end_y; sel_end_y = sel_y; sel_y = tmp; } */ if ((dx || dy)) { if (!shift) { if ((sel_end_x + dx) >= (col_count-1)) {dx=0;} //заглушка else if ((sel_end_y + dy) >= (row_count-1)) {dy=0;} else { move_sel(sel_x + dx, sel_y + dy); } } else { sel_moved = 0; stop_edit(); draw_grid(); } } }
command(TableUI *tui, int cmd) { switch (cmd) { case CmdClearFile: clear_file(tui); break; case CmdOpenFile: clear_and_open(tui, tui->filename); if (row_count(tui->table) < MAX_ROWS_FOR_FIT && max_col_count(tui->table) < MAX_COLS_FOR_FIT) { unsigned i; for (i = 0; i < max_col_count(tui->table); i++) auto_resize_col(tui, i); } break; case CmdSaveFile: save_csv(tui, tui->filename); break; case CmdSetAnchor: set_anchor(tui); break; case CmdClearAnchor: clear_anchor(tui); break; case CmdClearRow: clear_selected_rows(tui); break; case CmdDeleteRow: delete_selected_rows(tui); break; case CmdDeleteCell: delete_selected_cells(tui); break; case CmdClearCell: clear_selected_cells(tui); break; case CmdCopy: copy_to_clipboard(tui); break; case CmdCutClear: copy_to_clipboard(tui); clear_selected_cells(tui); break; case CmdCutDelete: copy_to_clipboard(tui); delete_selected_cells(tui); break; case CmdPaste: clear_anchor(tui); paste_clipboard(tui); break; case CmdReturn: clear_anchor(tui); move_cursor(tui, 1, 0); break; case CmdTab: clear_anchor(tui); move_cursor(tui, 0, 1); break; case CmdUnReturn: clear_anchor(tui); move_cursor(tui, -1, 0); break; case CmdUnTab: clear_anchor(tui); move_cursor(tui, 0, -1); break; case CmdEditCell: start_edit(tui, 1); break; case CmdEditCellClear: start_edit(tui, 0); break; case CmdCommitEdit: end_edit(tui); break; case CmdCancelEdit: cancel_edit(tui); break; case CmdMoveUp: move_cursor(tui, -1, 0); break; case CmdMoveDown: move_cursor(tui, 1, 0); break; case CmdMoveLeft: move_cursor(tui, 0, -1); break; case CmdMoveRight: move_cursor(tui, 0, 1); break; case CmdScrollUp: scroll(tui, -1, 0); break; case CmdScrollDown: scroll(tui, 1, 0); break; case CmdScrollLeft: scroll(tui, 0, -1); break; case CmdScrollRight: scroll(tui, 0, 1); break; case CmdHomeCol: jump_cursor(tui, 0, tui->cur_col); break; case CmdHomeRow: jump_cursor(tui, tui->cur_row, 0); break; case CmdEndCol: jump_cursor(tui, row_count(tui->table) - 1, tui->cur_col); break; case CmdEndRow: jump_cursor(tui, tui->cur_row, col_count(tui->table, tui->cur_row) - 1); break; case CmdInsertDate: insert_datetime(tui, 0); break; case CmdInsertDateTime: insert_datetime(tui, 1); break; case CmdInsertCell: insert_cells(tui->table, tui->cur_row, tui->cur_col, 1); redraw_rows(tui, tui->cur_row, tui->cur_row); break; case CmdInsertRow: insert_rows(tui->table, tui->cur_row, 1); redraw_rows(tui, tui->cur_row, -1); break; case CmdFindColumn: find_cell_text_col(tui, tui->cur_row, tui->cur_col, tui->find_text); break; case CmdFindRow: find_cell_text_row(tui, tui->cur_row, tui->cur_col, tui->find_text); break; } }