// File: /workspace/github_cpp_makefile_star2_O2/havluj[P]spreadsheet/src/CTableController.cpp
// Function: CTableController::renderTable()
void CTableController::renderTable() {
    int maxY, maxX;
    getmaxyx(stdscr, maxY, maxX);

    init_pair(2, COLOR_RED, COLOR_BLACK);
    init_pair(3, COLOR_BLUE, COLOR_BLACK);

    int rowsCnt = (maxY - 10 - 3) / 2;
    if ((rowsCnt + m_rowStartingPosition) < m_rowPosition) {
	  m_rowStartingPosition = m_rowPosition - rowsCnt;
    } else if (m_rowPosition < m_rowStartingPosition) {
	  m_rowStartingPosition = m_rowPosition;
    }

    int colsCnt = (maxX - 6) / 10;
    if ((colsCnt + m_colStartingPosition) <= m_colPosition) {
	  m_colStartingPosition = m_colPosition - colsCnt + 1;
    } else if (m_colPosition < m_colStartingPosition) {
	  m_colStartingPosition = m_colPosition;
    }

    //==========================================================================
    /* create the grid */
    //==========================================================================
    attrset(COLOR_PAIR(3));
    /* horizontal lines */
    int offset = 10;
    for (int i = m_rowStartingPosition; i < (rowsCnt + m_rowStartingPosition); i++) {
	  if (m_rowPosition == i || m_rowPosition == (i + 1)) {
		attrset(COLOR_PAIR(2));
	  }
	  move(offset, 0);
	  hline(0, maxX);
	  attroff(COLOR_PAIR(2));
	  attrset(COLOR_PAIR(3));
	  offset += 2;
    }

    /* vertical lines */
    offset = 5;
    for (int i = m_colStartingPosition; i <= (colsCnt + m_colStartingPosition); i++) {
	  if (m_colPosition == i || m_colPosition == (i - 1)) {
		attrset(COLOR_PAIR(2));
	  }
	  move(7, offset);
	  vline(0, maxY - 7 - 3);
	  attroff(COLOR_PAIR(2));
	  attrset(COLOR_PAIR(3));
	  offset += 10;
    }
    attroff(COLOR_PAIR(3));

    /* We need to draw the main lines after we draw the regular ones, so they
	 will appear to be in front of the regular ones. */
    /* Main vertical line */
    move(7, 4);
    vline(0, maxY - 7 - 3);

    /* Main horizontal line. */
    move(8, 0);
    hline('=', maxX);

    //==========================================================================
    /* numbering cols and rows */
    //==========================================================================
    /* rows */
    offset = 9;
    for (int i = m_rowStartingPosition; i <= (rowsCnt + m_rowStartingPosition); i++) {
	  if (m_rowPosition == i) {
		attrset(COLOR_PAIR(2));
	  }
	  mvprintw(offset, 0, "%4d", i);
	  attroff(COLOR_PAIR(2));
	  offset += 2;
    }

    /* columns */
    offset = 6;
    std::string s;
    int digitsCnt;
    for (int i = m_colStartingPosition; i <= (colsCnt + m_colStartingPosition); i++) {
	  /* center the numbers */
	  s = "";
	  digitsCnt = std::to_string(i).length();
	  for (int j = 0; j < ((9 - digitsCnt) / 2); j++) {
		s.append(" ");
	  }
	  s.append(std::to_string(i));
	  for (int j = (s.length()); j < 9; j++) {
		s.append(" ");
	  }

	  if (m_colPosition == i) {
		attrset(COLOR_PAIR(2));
	  }
	  /* make sure to display only a part if there is not enough space */
	  if ((int) s.length() > (maxX - offset)) {
		mvprintw(7, offset, "%.*s", (maxX - offset), s.c_str());
	  } else {
		mvprintw(7, offset, "%s", s.c_str());
	  }
	  attroff(COLOR_PAIR(2));
	  offset += 10;
    }

    //==========================================================================
    /* filling out the table */
    //==========================================================================
    int rowOffset = 9;
    for (int i = m_rowStartingPosition; i <= (rowsCnt + m_rowStartingPosition); i++) {
	  int colOffset = 6;
	  for (int j = m_colStartingPosition; j <= (colsCnt + m_colStartingPosition); j++) {
		/* center the content */
		s = "";
		digitsCnt = m_database.getValue(i, j).length();
		for (int k = 0; k < ((9 - digitsCnt) / 2); k++) {
		    s.append(" ");
		}
		s.append(m_database.getValue(i, j));
		for (int k = (s.length()); k < 9; k++) {
		    s.append(" ");
		}

		/* keep only 9 characters */
		if (s.length() > 9) {
		    s = s.substr(0, 6);
		    s.append("...");
		}

		if (m_colPosition == j && m_rowPosition == i) {
		    attrset(COLOR_PAIR(2));
		}
		/* make sure to display only a part if there is not enough space */
		if ((int) s.length() > (maxX - colOffset)) {
		    mvprintw(rowOffset, colOffset, "%.*s", (maxX - colOffset), s.c_str());
		} else {
		    mvprintw(rowOffset, colOffset, "%s", s.c_str());
		}
		attroff(COLOR_PAIR(2));
		colOffset += 10;
	  }
	  rowOffset += 2;
    }

    refresh();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, 0x8(%rsp)
movq 0xa320(%rip), %rax      # 0x12fb8
movq (%rax), %rax
testq %rax, %rax
je 0x8cb0
movswl 0x4(%rax), %r13d
incl %r13d
movswl 0x6(%rax), %eax
incl %eax
jmp 0x8cb7
pushq $-0x1
popq %r13
movl %r13d, %eax
movq %rax, 0x18(%rsp)
pushq $0x2
popq %rbx
pushq $0x1
popq %rsi
movl %ebx, %edi
xorl %edx, %edx
callq 0x4050
pushq $0x3
popq %rdi
pushq $0x4
popq %rsi
xorl %edx, %edx
callq 0x4050
leal -0xd(%r13), %eax
cltd
idivl %ebx
movl %eax, %r12d
movq 0x8(%rsp), %rcx
movl 0x78(%rcx), %eax
movl 0x80(%rcx), %ecx
leal (%rcx,%r12), %edx
cmpl %eax, %edx
jge 0x8d02
subl %r12d, %eax
movq 0x8(%rsp), %rcx
jmp 0x8d0b
cmpl %ecx, %eax
movq 0x8(%rsp), %rcx
jge 0x8d11
movl %eax, 0x80(%rcx)
movq 0x18(%rsp), %rax
addl $-0x6, %eax
pushq $0xa
popq %rbx
cltd
idivl %ebx
movl %eax, %r15d
movl 0x7c(%rcx), %eax
movl 0x84(%rcx), %ecx
leal (%rcx,%r15), %edx
cmpl %eax, %edx
jle 0x8d3e
cmpl %ecx, %eax
movq 0x8(%rsp), %r14
jl 0x8d48
jmp 0x8d4f
subl %r15d, %eax
incl %eax
movq 0x8(%rsp), %r14
movl %eax, 0x84(%r14)
movq 0xa262(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x300, %esi            # imm = 0x300
callq 0x4360
movl 0x80(%r14), %eax
movl %eax, %ebp
addl %r12d, %eax
cmpl %eax, %ebp
jge 0x8dec
movq 0x8(%rsp), %rax
movl 0x78(%rax), %eax
cmpl %eax, %ebp
sete %cl
incl %ebp
cmpl %eax, %ebp
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x8da1
movq 0xa224(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4360
movl %ebx, %edi
xorl %esi, %esi
callq 0x4210
movq 0xa207(%rip), %r14      # 0x12fb8
movq (%r14), %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x42d0
movq (%r14), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43e0
movq (%r14), %rdi
movl $0x300, %esi            # imm = 0x300
callq 0x4360
addl $0x2, %ebx
movq 0x8(%rsp), %rax
movl 0x80(%rax), %eax
jmp 0x8d6c
movq 0x8(%rsp), %rax
movl 0x84(%rax), %eax
addl $-0xa, %r13d
pushq $0x5
popq %rbx
pushq $0x7
popq %rbp
movl %eax, %r14d
movq %r15, 0x20(%rsp)
addl %r15d, %eax
cmpl %eax, %r14d
jg 0x8e9b
movq 0x8(%rsp), %rax
movl 0x7c(%rax), %eax
cmpl %r14d, %eax
sete %cl
decl %r14d
cmpl %r14d, %eax
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x8e46
movq 0xa17f(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4360
movl %ebp, %edi
movl %ebx, %esi
callq 0x4210
movq 0xa162(%rip), %r15      # 0x12fb8
movq (%r15), %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x43c0
movq (%r15), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43e0
movq (%r15), %rdi
movl $0x300, %esi            # imm = 0x300
callq 0x4360
addl $0xa, %ebx
movq 0x8(%rsp), %rax
movl 0x84(%rax), %eax
addl $0x2, %r14d
movq 0x20(%rsp), %r15
jmp 0x8e09
movq 0xa116(%rip), %rbx      # 0x12fb8
movq (%rbx), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x43e0
pushq $0x7
popq %rdi
pushq $0x4
popq %rsi
callq 0x4210
movq (%rbx), %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x43c0
pushq $0x8
popq %rdi
xorl %esi, %esi
callq 0x4210
movq (%rbx), %rdi
pushq $0x3d
popq %rsi
movq 0x18(%rsp), %rdx
callq 0x42d0
movq 0x8(%rsp), %rax
movl 0x80(%rax), %eax
pushq $0x9
popq %rbx
leaq 0x47b9(%rip), %r14      # 0xd6b1
movl %eax, %ebp
addl %r12d, %eax
cmpl %eax, %ebp
jg 0x8f57
movq 0x8(%rsp), %rax
cmpl 0x78(%rax), %ebp
jne 0x8f1f
movq 0xa0a6(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4360
movl %ebx, %edi
xorl %esi, %esi
movq %r14, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x4410
movq 0xa082(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43e0
addl $0x2, %ebx
incl %ebp
movq 0x8(%rsp), %rax
movl 0x80(%rax), %eax
jmp 0x8efa
movq %r12, 0x50(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x8(%rsp), %rax
movl 0x84(%rax), %eax
pushq $0x6
popq %rbx
leaq 0x30(%rsp), %r15
leaq 0x58(%rsp), %r12
leaq 0x48c7(%rip), %r13      # 0xd853
movl %eax, %r14d
movq 0x20(%rsp), %rcx
addl %eax, %ecx
cmpl %ecx, %r14d
jg 0x90ae
movq %r15, %rdi
leaq 0x48ab(%rip), %rsi      # 0xd854
callq 0x4610
movq %r12, %rdi
movl %r14d, %esi
callq 0x94dd
pushq $0x9
popq %rbp
subl 0x60(%rsp), %ebp
movq %r12, %rdi
callq 0x4150
movl %ebp, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %ebp
testl %eax, %eax
movl $0x0, %eax
cmovlel %eax, %ebp
subl $0x1, %ebp
jb 0x8fee
movq %r15, %rdi
movq %r13, %rsi
callq 0x4600
jmp 0x8fdc
movq %r12, %rdi
movl %r14d, %esi
callq 0x94dd
movq %r15, %rdi
movq %r12, %rsi
callq 0x4630
movq %r12, %rdi
callq 0x4150
movl 0x38(%rsp), %ebp
cmpl $0x9, %ebp
jge 0x9024
movq %r15, %rdi
movq %r13, %rsi
callq 0x4600
incl %ebp
jmp 0x9010
movq 0x8(%rsp), %rax
cmpl %r14d, 0x7c(%rax)
jne 0x9043
movq 0x9f82(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4360
movq 0x18(%rsp), %rax
movl %eax, %ecx
subl %ebx, %ecx
movq 0x30(%rsp), %r8
cmpl 0x38(%rsp), %ecx
jge 0x906c
pushq $0x7
popq %rdi
movl %ebx, %esi
leaq 0x4652(%rip), %rdx      # 0xd6b5
xorl %eax, %eax
callq 0x4410
jmp 0x9082
pushq $0x7
popq %rdi
movl %ebx, %esi
leaq 0x4617(%rip), %rdx      # 0xd68f
movq %r8, %rcx
xorl %eax, %eax
callq 0x4410
movq 0x9f2f(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43e0
addl $0xa, %ebx
incl %r14d
movq 0x8(%rsp), %rax
movl 0x84(%rax), %eax
jmp 0x8f8f
movq 0x8(%rsp), %rdx
movl 0x80(%rdx), %ecx
addq $0x8, %rdx
movq %rdx, 0x28(%rsp)
leaq 0x30(%rsp), %rbp
leaq 0x58(%rsp), %r14
leaq 0x4780(%rip), %r12      # 0xd853
pushq $0x9
popq %rdx
movl %edx, 0x14(%rsp)
movl %ecx, %edx
addl 0x50(%rsp), %ecx
movl %edx, 0x10(%rsp)
cmpl %ecx, %edx
jg 0x928d
pushq $0x6
popq %r15
movl %eax, %r13d
movq 0x20(%rsp), %rcx
addl %eax, %ecx
cmpl %ecx, %r13d
jg 0x9272
movq %rbp, %rdi
leaq 0x4747(%rip), %rsi      # 0xd854
callq 0x4610
movq %r14, %rdi
movq 0x28(%rsp), %rsi
movl 0x10(%rsp), %edx
movl %r13d, %ecx
callq 0x5b2c
pushq $0x9
popq %rbx
subl 0x60(%rsp), %ebx
movq %r14, %rdi
callq 0x4150
movl %ebx, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %ebx
testl %eax, %eax
movl $0x0, %eax
cmovlel %eax, %ebx
subl $0x1, %ebx
jb 0x915b
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4600
jmp 0x9149
movq %r14, %rdi
movq 0x28(%rsp), %rsi
movl 0x10(%rsp), %edx
movl %r13d, %ecx
callq 0x5b2c
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4630
movq %r14, %rdi
callq 0x4150
movl 0x38(%rsp), %ebx
cmpl $0x9, %ebx
jge 0x919a
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4600
incl %ebx
jmp 0x9186
cmpq $0x9, 0x38(%rsp)
jbe 0x91d4
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
pushq $0x6
popq %rcx
callq 0x4330
movq %rbp, %rdi
movq %r14, %rsi
callq 0x43b0
movq %r14, %rdi
callq 0x4150
movq %rbp, %rdi
leaq 0x44eb(%rip), %rsi      # 0xd6ba
callq 0x4600
movq 0x8(%rsp), %rax
cmpl %r13d, 0x7c(%rax)
jne 0x9201
movq 0x8(%rsp), %rax
movl 0x10(%rsp), %ecx
cmpl %ecx, 0x78(%rax)
jne 0x9201
movq 0x9dc4(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4360
movq 0x18(%rsp), %rax
movl %eax, %ecx
subl %r15d, %ecx
movq 0x30(%rsp), %r8
cmpl 0x38(%rsp), %ecx
jge 0x922d
movl 0x14(%rsp), %edi
movl %r15d, %esi
leaq 0x4491(%rip), %rdx      # 0xd6b5
xorl %eax, %eax
callq 0x4410
jmp 0x9245
movl 0x14(%rsp), %edi
movl %r15d, %esi
leaq 0x4454(%rip), %rdx      # 0xd68f
movq %r8, %rcx
xorl %eax, %eax
callq 0x4410
movq 0x9d6c(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43e0
addl $0xa, %r15d
incl %r13d
movq 0x8(%rsp), %rax
movl 0x84(%rax), %eax
jmp 0x90f3
addl $0x2, 0x14(%rsp)
movl 0x10(%rsp), %edx
incl %edx
movq 0x8(%rsp), %rcx
movl 0x80(%rcx), %ecx
jmp 0x90dc
callq 0x4550
leaq 0x30(%rsp), %rdi
callq 0x4150
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x92d2
jmp 0x92b9
jmp 0x92d2
jmp 0x92d2
jmp 0x92d2
jmp 0x92d2
jmp 0x92d2
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4150
jmp 0x92d5
jmp 0x92d2
jmp 0x92d2
jmp 0x92d2
jmp 0x92d2
jmp 0x92d2
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x4150
movq %rbx, %rdi
callq 0x4590
nop