diff --git a/Windows/GEDebugger/GEDebugger.cpp b/Windows/GEDebugger/GEDebugger.cpp index 4083f06a45..a9ac468e81 100644 --- a/Windows/GEDebugger/GEDebugger.cpp +++ b/Windows/GEDebugger/GEDebugger.cpp @@ -125,7 +125,8 @@ CGEDebugger::CGEDebugger(HINSTANCE _hInstance, HWND _hParent) MapWindowPoints(HWND_DESKTOP,m_hDlg,(LPPOINT)&frameRect,2); MoveWindow(frameWnd,frameRect.left,frameRect.top,512,272,TRUE); - HWND wnd = AddTabWindow(L"CtrlDisplayListView",L"Display List"); + tabs = new TabControl(GetDlgItem(m_hDlg,IDC_GEDBG_MAINTAB)); + HWND wnd = tabs->AddTabWindow(L"CtrlDisplayListView",L"Display List"); displayList = CtrlDisplayListView::getFrom(wnd); // set window position @@ -187,95 +188,6 @@ void CGEDebugger::UpdatePreviews() { } } -HWND CGEDebugger::AddTabWindow(wchar_t* className, wchar_t* title, DWORD style) -{ - HWND tabControl = GetDlgItem(m_hDlg,IDC_GEDBG_MAINTAB); - style |= WS_CHILD; - - TCITEM tcItem; - ZeroMemory (&tcItem,sizeof (tcItem)); - tcItem.mask = TCIF_TEXT; - tcItem.dwState = 0; - tcItem.pszText = title; - tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1; - tcItem.iImage = 0; - - int index = TabCtrl_GetItemCount(tabControl); - int result = TabCtrl_InsertItem(tabControl,index,&tcItem); - - RECT tabRect; - GetWindowRect(tabControl,&tabRect); - MapWindowPoints(HWND_DESKTOP,m_hDlg,(LPPOINT)&tabRect,2); - TabCtrl_AdjustRect(tabControl, FALSE, &tabRect); - - HWND hwnd = CreateWindowEx(0,className,title,style, - tabRect.left,tabRect.top,tabRect.right-tabRect.left,tabRect.bottom-tabRect.top, - m_hDlg,0,MainWindow::GetHInstance(),0); - tabs.push_back(hwnd); - - ShowTab(index); - return hwnd; -} - -void CGEDebugger::AddTabDialog(Dialog* dialog, wchar_t* title) -{ - HWND tabControl = GetDlgItem(m_hDlg,IDC_GEDBG_MAINTAB); - HWND handle = dialog->GetDlgHandle(); - - TCITEM tcItem; - ZeroMemory (&tcItem,sizeof (tcItem)); - tcItem.mask = TCIF_TEXT; - tcItem.dwState = 0; - tcItem.pszText = title; - tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1; - tcItem.iImage = 0; - - int index = TabCtrl_GetItemCount(tabControl); - int result = TabCtrl_InsertItem(tabControl,index,&tcItem); - - RECT tabRect; - GetWindowRect(tabControl,&tabRect); - MapWindowPoints(HWND_DESKTOP,m_hDlg,(LPPOINT)&tabRect,2); - TabCtrl_AdjustRect(tabControl, FALSE, &tabRect); - - SetParent(handle,m_hDlg); - DWORD style = (GetWindowLong(handle,GWL_STYLE) | WS_CHILD) & ~(WS_POPUP | WS_TILEDWINDOW); - SetWindowLong(handle, GWL_STYLE, style); - MoveWindow(handle,tabRect.left,tabRect.top,tabRect.right-tabRect.left,tabRect.bottom-tabRect.top,TRUE); - tabs.push_back(handle); - - ShowTab(index); -} - -void CGEDebugger::ShowTab(int index, bool setControlIndex) -{ - HWND tabControl = GetDlgItem(m_hDlg,IDC_GEDBG_MAINTAB); - - for (size_t i = 0; i < tabs.size(); i++) - { - ShowWindow(tabs[i],i == index ? SW_NORMAL : SW_HIDE); - } - - if (setControlIndex) - { - TabCtrl_SetCurSel(tabControl,index); - } -} - -void CGEDebugger::ShowTab(HWND pageHandle) -{ - HWND tabControl = GetDlgItem(m_hDlg,IDC_GEDBG_MAINTAB); - - for (size_t i = 0; i < tabs.size(); i++) - { - if (tabs[i] == pageHandle) - { - TabCtrl_SetCurSel(tabControl,i); - } - ShowWindow(tabs[i],tabs[i] == pageHandle ? SW_NORMAL : SW_HIDE); - } -} - void CGEDebugger::UpdateSize(WORD width, WORD height) { // only resize the tab for now @@ -288,24 +200,6 @@ void CGEDebugger::UpdateSize(WORD width, WORD height) tabRect.right = tabRect.left + (width-tabRect.left*2); // assume same gap on both sides tabRect.bottom = tabRect.top + (height-tabRect.top-tabRect.left); // assume same gap on bottom too MoveWindow(tabControl,tabRect.left,tabRect.top,tabRect.right-tabRect.left,tabRect.bottom-tabRect.top,TRUE); - InvalidateRect(tabControl,NULL,FALSE); - UpdateWindow(tabControl); - - // now resize tab children - TabCtrl_AdjustRect(tabControl, FALSE, &tabRect); - int current = TabCtrl_GetCurSel(tabControl); - - for (int i = 0; i < tabs.size(); i++) - { - InvalidateRect(tabs[i],NULL,FALSE); - MoveWindow(tabs[i],tabRect.left,tabRect.top,tabRect.right-tabRect.left,tabRect.bottom-tabRect.top,FALSE); - - if (i == current) - { - InvalidateRect(tabs[i],NULL,FALSE); - UpdateWindow(tabs[i]); - } - } } void CGEDebugger::SavePosition() @@ -360,16 +254,7 @@ BOOL CGEDebugger::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (wParam) { case IDC_GEDBG_MAINTAB: - { - HWND tabControl = GetDlgItem(m_hDlg, IDC_GEDBG_MAINTAB); - NMHDR* pNotifyMessage = NULL; - pNotifyMessage = (LPNMHDR)lParam; - if (pNotifyMessage->hwndFrom == tabControl) - { - int iPage = TabCtrl_GetCurSel(tabControl); - ShowTab(iPage,false); - } - } + tabs->HandleNotify(lParam); break; } break; diff --git a/Windows/GEDebugger/GEDebugger.h b/Windows/GEDebugger/GEDebugger.h index f267f88e0f..d50a273ebc 100644 --- a/Windows/GEDebugger/GEDebugger.h +++ b/Windows/GEDebugger/GEDebugger.h @@ -21,6 +21,7 @@ #include "Globals.h" #include "Windows/resource.h" #include "Windows/W32Util/DialogManager.h" +#include "Windows/W32Util/TabControl.h" #include "Windows/GEDebugger/SimpleGLWindow.h" enum { @@ -43,17 +44,13 @@ protected: private: void SetupPreviews(); void UpdatePreviews(); - HWND AddTabWindow(wchar_t* className, wchar_t* title, DWORD style = 0); - void AddTabDialog(Dialog* dialog, wchar_t* title); - void ShowTab(int index, bool setControlIndex = true); - void ShowTab(HWND pageHandle); void UpdateSize(WORD width, WORD height); void SavePosition(); CtrlDisplayListView* displayList; SimpleGLWindow *frameWindow; SimpleGLWindow *texWindow; - std::vector tabs; + TabControl* tabs; int minWidth,minHeight; }; diff --git a/Windows/PPSSPP.vcxproj b/Windows/PPSSPP.vcxproj index f197d3f570..53d56b2f44 100644 --- a/Windows/PPSSPP.vcxproj +++ b/Windows/PPSSPP.vcxproj @@ -296,6 +296,7 @@ + @@ -334,6 +335,7 @@ + diff --git a/Windows/PPSSPP.vcxproj.filters b/Windows/PPSSPP.vcxproj.filters index caf6aae59e..03023ca09d 100644 --- a/Windows/PPSSPP.vcxproj.filters +++ b/Windows/PPSSPP.vcxproj.filters @@ -122,6 +122,9 @@ Windows\GE Debugger + + Windows\W32Util + @@ -218,6 +221,9 @@ Windows\GE Debugger + + Windows\W32Util + diff --git a/Windows/W32Util/TabControl.cpp b/Windows/W32Util/TabControl.cpp new file mode 100644 index 0000000000..ff269ee65a --- /dev/null +++ b/Windows/W32Util/TabControl.cpp @@ -0,0 +1,162 @@ +#include "TabControl.h" +#include "DialogManager.h" +#include "Windows/WndMainWindow.h" +#include +#include + +TabControl::TabControl(HWND handle): hwnd(handle) +{ + SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)this); + oldProc = (WNDPROC) SetWindowLongPtr(hwnd,GWLP_WNDPROC,(LONG_PTR)wndProc); + +} + +HWND TabControl::AddTabWindow(wchar_t* className, wchar_t* title, DWORD style) +{ + style |= WS_CHILD; + + TCITEM tcItem; + ZeroMemory (&tcItem,sizeof (tcItem)); + tcItem.mask = TCIF_TEXT; + tcItem.dwState = 0; + tcItem.pszText = title; + tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1; + tcItem.iImage = 0; + + int index = TabCtrl_GetItemCount(hwnd); + int result = TabCtrl_InsertItem(hwnd,index,&tcItem); + + RECT tabRect; + GetWindowRect(hwnd,&tabRect); + MapWindowPoints(HWND_DESKTOP,GetParent(hwnd),(LPPOINT)&tabRect,2); + TabCtrl_AdjustRect(hwnd, FALSE, &tabRect); + + HWND tabHandle = CreateWindowEx(0,className,title,style, + tabRect.left,tabRect.top,tabRect.right-tabRect.left,tabRect.bottom-tabRect.top, + GetParent(hwnd),0,MainWindow::GetHInstance(),0); + tabs.push_back(tabHandle); + + ShowTab(index); + return tabHandle; +} + +void TabControl::AddTabDialog(Dialog* dialog, wchar_t* title) +{ + HWND handle = dialog->GetDlgHandle(); + + TCITEM tcItem; + ZeroMemory (&tcItem,sizeof (tcItem)); + tcItem.mask = TCIF_TEXT; + tcItem.dwState = 0; + tcItem.pszText = title; + tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1; + tcItem.iImage = 0; + + int index = TabCtrl_GetItemCount(hwnd); + int result = TabCtrl_InsertItem(hwnd,index,&tcItem); + + RECT tabRect; + GetWindowRect(hwnd,&tabRect); + MapWindowPoints(HWND_DESKTOP,GetParent(hwnd),(LPPOINT)&tabRect,2); + TabCtrl_AdjustRect(hwnd, FALSE, &tabRect); + + SetParent(handle,GetParent(hwnd)); + DWORD style = (GetWindowLong(handle,GWL_STYLE) | WS_CHILD) & ~(WS_POPUP | WS_TILEDWINDOW); + SetWindowLong(handle, GWL_STYLE, style); + MoveWindow(handle,tabRect.left,tabRect.top,tabRect.right-tabRect.left,tabRect.bottom-tabRect.top,TRUE); + tabs.push_back(handle); + + ShowTab(index); +} + +void TabControl::ShowTab(int index, bool setControlIndex) +{ + for (size_t i = 0; i < tabs.size(); i++) + { + ShowWindow(tabs[i],i == index ? SW_NORMAL : SW_HIDE); + } + + if (setControlIndex) + { + TabCtrl_SetCurSel(hwnd,index); + } +} + +void TabControl::ShowTab(HWND pageHandle) +{ + for (size_t i = 0; i < tabs.size(); i++) + { + if (tabs[i] == pageHandle) + { + TabCtrl_SetCurSel(hwnd,i); + } + ShowWindow(tabs[i],tabs[i] == pageHandle ? SW_NORMAL : SW_HIDE); + } +} + +void TabControl::NextTab(bool cycle) +{ + int index = TabCtrl_GetCurSel(hwnd); + if (index == tabs.size()-1 && cycle) + index = 0; + ShowTab(index); +} + +void TabControl::PreviousTab(bool cycle) +{ + int index = TabCtrl_GetCurSel(hwnd); + if (index == 0 && cycle) + index = tabs.size()-1; + ShowTab(index); +} + +void TabControl::HandleNotify(LPARAM lParam) +{ + NMHDR* pNotifyMessage = NULL; + pNotifyMessage = (LPNMHDR)lParam; + if (pNotifyMessage->hwndFrom == hwnd) + { + int iPage = TabCtrl_GetCurSel(hwnd); + ShowTab(iPage,false); + } +} + +void TabControl::OnResize() +{ + RECT tabRect; + GetWindowRect(hwnd,&tabRect); + MapWindowPoints(HWND_DESKTOP,GetParent(hwnd),(LPPOINT)&tabRect,2); + + InvalidateRect(hwnd,NULL,FALSE); + UpdateWindow(hwnd); + + // now resize tab children + TabCtrl_AdjustRect(hwnd, FALSE, &tabRect); + int current = TabCtrl_GetCurSel(hwnd); + + for (size_t i = 0; i < tabs.size(); i++) + { + InvalidateRect(tabs[i],NULL,FALSE); + MoveWindow(tabs[i],tabRect.left,tabRect.top,tabRect.right-tabRect.left,tabRect.bottom-tabRect.top,FALSE); + + if (i == current) + { + InvalidateRect(tabs[i],NULL,FALSE); + UpdateWindow(tabs[i]); + } + } +} + +LRESULT CALLBACK TabControl::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + TabControl* tabControl = (TabControl*) GetWindowLongPtr(hwnd,GWLP_USERDATA); + + switch (msg) + { + case WM_SIZE: + tabControl->OnResize(); + break; + } + + return (LRESULT)CallWindowProc((WNDPROC)tabControl->oldProc,hwnd,msg,wParam,lParam); +} \ No newline at end of file diff --git a/Windows/W32Util/TabControl.h b/Windows/W32Util/TabControl.h new file mode 100644 index 0000000000..ba3557c048 --- /dev/null +++ b/Windows/W32Util/TabControl.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +class Dialog; + +class TabControl +{ +public: + TabControl(HWND handle); + void HandleNotify(LPARAM lParam); + HWND AddTabWindow(wchar_t* className, wchar_t* title, DWORD style = 0); + void AddTabDialog(Dialog* dialog, wchar_t* title); + void ShowTab(int index, bool setControlIndex = true); + void ShowTab(HWND pageHandle); + void NextTab(bool cycle); + void PreviousTab(bool cycle); +private: + static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + void OnResize(); + HWND hwnd; + WNDPROC oldProc; + std::vector tabs; +}; \ No newline at end of file