mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Move tab control into separate class
This commit is contained in:
parent
c4dbe37444
commit
72faf8c8ab
6 changed files with 199 additions and 123 deletions
|
@ -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;
|
||||
|
|
|
@ -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<HWND> tabs;
|
||||
TabControl* tabs;
|
||||
|
||||
int minWidth,minHeight;
|
||||
};
|
||||
|
|
|
@ -296,6 +296,7 @@
|
|||
<ClCompile Include="W32Util\PropertySheet.cpp" />
|
||||
<ClCompile Include="W32Util\ShellUtil.cpp" />
|
||||
<ClCompile Include="InputBox.cpp" />
|
||||
<ClCompile Include="W32Util\TabControl.cpp" />
|
||||
<ClCompile Include="WndMainWindow.cpp" />
|
||||
<ClCompile Include="DSoundStream.cpp" />
|
||||
<ClCompile Include="OpenGLBase.cpp" />
|
||||
|
@ -334,6 +335,7 @@
|
|||
<ClInclude Include="W32Util\Misc.h" />
|
||||
<ClInclude Include="W32Util\PropertySheet.h" />
|
||||
<ClInclude Include="W32Util\ShellUtil.h" />
|
||||
<ClInclude Include="W32Util\TabControl.h" />
|
||||
<ClInclude Include="W32Util\XPTheme.h" />
|
||||
<ClInclude Include="InputBox.h" />
|
||||
<ClInclude Include="WndMainWindow.h" />
|
||||
|
|
|
@ -122,6 +122,9 @@
|
|||
<ClCompile Include="GEDebugger\CtrlDisplayListView.cpp">
|
||||
<Filter>Windows\GE Debugger</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="W32Util\TabControl.cpp">
|
||||
<Filter>Windows\W32Util</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Debugger\CtrlDisAsmView.h">
|
||||
|
@ -218,6 +221,9 @@
|
|||
<ClInclude Include="GEDebugger\CtrlDisplayListView.h">
|
||||
<Filter>Windows\GE Debugger</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="W32Util\TabControl.h">
|
||||
<Filter>Windows\W32Util</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="icon1.ico">
|
||||
|
|
162
Windows/W32Util/TabControl.cpp
Normal file
162
Windows/W32Util/TabControl.cpp
Normal file
|
@ -0,0 +1,162 @@
|
|||
#include "TabControl.h"
|
||||
#include "DialogManager.h"
|
||||
#include "Windows/WndMainWindow.h"
|
||||
#include <windowsx.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
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);
|
||||
}
|
24
Windows/W32Util/TabControl.h
Normal file
24
Windows/W32Util/TabControl.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
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<HWND> tabs;
|
||||
};
|
Loading…
Add table
Reference in a new issue