Skip to content

Commit

Permalink
Add tabulating functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
makuke1234 committed Jan 17, 2022
1 parent 9cc23c6 commit 1ba857b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The x86 (32-bit) Windows binaries can be downloaded [here](https://github.com/ma
* 0.2.0 (planned)
* Refactor codebase
* Upgrade PDFium version
* Tabulating using Ctrl+Tab & Ctrl+Shift+Tab
* [ ] Fix most bugs (hopefully)
* [ ] More optimised rendering

Expand Down
32 changes: 30 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ LRESULT CALLBACK pdfv::MainWindow::windowProc(const HWND hwnd, const UINT uMsg,
aboutBox();
}
break;
case IDC_TABULATE:
{
ssize_t idx = mwnd.m_tabs.m_tabindex + 1;
if (idx == ssize_t(mwnd.m_tabs.size()))
{
idx = 0;
}
mwnd.m_tabs.select(idx);
break;
}
case IDC_TABULATEBACK:
{
ssize_t idx = mwnd.m_tabs.m_tabindex - 1;
if (idx == -1)
{
idx = mwnd.m_tabs.size() - 1;
}
mwnd.m_tabs.select(idx);
break;
}
default:
if (wp >= IDM_LIMIT && wp < (IDM_LIMIT + mwnd.m_tabs.size()))
{
Expand Down Expand Up @@ -212,7 +232,7 @@ LRESULT CALLBACK pdfv::MainWindow::windowProc(const HWND hwnd, const UINT uMsg,
POINT p;
::GetCursorPos(&p);
auto pt1{ xy<int>{ p.x, p.y } - mwnd.m_pos };
auto pt2{ mwnd.m_tabs.m_pos + mwnd.m_tabs.m_offset };
auto pt2{ mwnd.m_tabs.m_pos + mwnd.m_tabs.m_offset };
auto sz { mwnd.m_tabs.m_size - mwnd.m_tabs.m_offset };

short dir = delta > 0 ? SB_LINEUP : SB_LINEDOWN;
Expand All @@ -232,8 +252,16 @@ LRESULT CALLBACK pdfv::MainWindow::windowProc(const HWND hwnd, const UINT uMsg,
break;
}
case WM_NOTIFY:
switch (reinterpret_cast<LPNMHDR>(lp)->code)
switch (reinterpret_cast<NMHDR *>(lp)->code)
{
case TCN_KEYDOWN:
{
auto kd = reinterpret_cast<NMTCKEYDOWN *>(lp);
::SendMessageW(hwnd, WM_KEYDOWN, kd->wVKey, kd->flags);
break;
}
case TCN_SELCHANGING:
return FALSE;
case TCN_SELCHANGE:
mwnd.m_tabs.selChange();
break;
Expand Down
3 changes: 3 additions & 0 deletions src/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#define IDM_LIMIT 121

#define IDC_TABULATE 122
#define IDC_TABULATEBACK 123


#define IDR_ACCELERATOR1 200

Expand Down
2 changes: 2 additions & 0 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ BEGIN
"W", IDM_FILE_CLOSETAB, CONTROL, VIRTKEY
"Q", IDM_FILE_EXIT, CONTROL, VIRTKEY
VK_F1, IDM_HELP_ABOUT, VIRTKEY
VK_TAB, IDC_TABULATE, CONTROL, VIRTKEY
VK_TAB, IDC_TABULATEBACK, CONTROL, SHIFT, VIRTKEY
END
27 changes: 21 additions & 6 deletions src/tabs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ LRESULT CALLBACK pdfv::TabObject::closeButtonProc(
{
switch (uMsg)
{
case WM_DRAWITEM:
{
auto pDIS = reinterpret_cast<DRAWITEMSTRUCT *>(lp);

FillRect(pDIS->hDC, &pDIS->rcItem, static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)));

return TRUE;
}
case WM_LBUTTONUP:
{
// Checks if mouse is in the right position
Expand Down Expand Up @@ -361,7 +369,7 @@ pdfv::Tabs::~Tabs() noexcept

[[nodiscard]] HWND pdfv::Tabs::createCloseButton(RECT sz, HMENU menu) const noexcept
{
auto ret = ::CreateWindowExW(
auto btn = ::CreateWindowExW(
0,
L"button",
L"X",
Expand All @@ -375,14 +383,19 @@ pdfv::Tabs::~Tabs() noexcept
pdfv::MainWindow::mwnd.getHinst(),
nullptr
);
if (btn == nullptr) [[unlikely]]
{
return nullptr;
}

::SendMessageW(
ret,
btn,
WM_SETFONT,
reinterpret_cast<WPARAM>(pdfv::MainWindow::mwnd.getDefaultFont()),
true
);
::SetWindowSubclass(ret, &pdfv::TabObject::closeButtonProc, 1, 0);
return ret;
::SetWindowSubclass(btn, &pdfv::TabObject::closeButtonProc, 1, 0);
return btn;
}

void pdfv::Tabs::resize(xy<int> newsize) noexcept
Expand All @@ -394,7 +407,7 @@ void pdfv::Tabs::resize(xy<int> newsize) noexcept
this->m_tabs[this->m_tabindex].tabhandle,
this->m_offset.x, this->m_offset.y,
this->m_size.x - this->m_offset.x, this->m_size.y - this->m_offset.y,
true
TRUE
);
}

Expand Down Expand Up @@ -602,8 +615,10 @@ void pdfv::Tabs::select(const ssize_t index) noexcept
}
void pdfv::Tabs::selChange() noexcept
{
this->m_tabs[this->m_tabindex].hide();
auto oldidx = this->m_tabindex;
this->m_tabindex = TabCtrl_GetCurSel(this->m_tabshwnd);

this->m_tabs[oldidx].hide();
this->resize(this->m_size);
this->m_tabs[this->m_tabindex].show();
}
4 changes: 2 additions & 2 deletions src/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#define PRODUCT_NAME L"PdfiumView"
#define APP_NAME PRODUCT_NAME L" v" VERSION_STRING

#define VERSION_SEQUENCE 0,1,0,0
#define VERSION_SEQUENCE_STR "0.1.0.0"
#define VERSION_SEQUENCE 0,1,2
#define VERSION_SEQUENCE_STR "0.1.2"

#define DEFAULT_OPEN_FILTER L""
#define DEFAULT_OPEN_TITLE L""

0 comments on commit 1ba857b

Please sign in to comment.