4.30 beta

This commit is contained in:
Igor Pavlov
2005-11-18 00:00:00 +00:00
committed by Kornel Lesiński
parent bcd1db2f5a
commit e18587ba51
214 changed files with 5385 additions and 2712 deletions

View File

@@ -1,23 +1,63 @@
// Windows/Control/ComboBox.cpp
// #define _UNICODE
// #define UNICODE
#include "StdAfx.h"
#ifndef _UNICODE
#include "Common/StringConvert.h"
#endif
#include "Windows/Control/ComboBox.h"
#include "Windows/Defs.h"
#ifndef _UNICODE
extern bool g_IsNT;
#endif
namespace NWindows {
namespace NControl {
int CComboBox::GetLBText(int index, CSysString &string)
LRESULT CComboBox::GetLBText(int index, CSysString &s)
{
string.Empty();
int aLength = GetLBTextLen(index);
if (aLength == CB_ERR)
return aLength;
aLength = GetLBText(index, string.GetBuffer(aLength));
string.ReleaseBuffer();
return aLength;
s.Empty();
LRESULT len = GetLBTextLen(index);
if (len == CB_ERR)
return len;
len = GetLBText(index, s.GetBuffer((int)len + 1));
s.ReleaseBuffer();
return len;
}
#ifndef _UNICODE
LRESULT CComboBox::AddString(LPCWSTR s)
{
if (g_IsNT)
return SendMessageW(CB_ADDSTRING, 0, (LPARAM)s);
return AddString(GetSystemString(s));
}
LRESULT CComboBox::GetLBText(int index, UString &s)
{
s.Empty();
if (g_IsNT)
{
LRESULT len = SendMessageW(CB_GETLBTEXTLEN, index, 0);
if (len == CB_ERR)
return len;
len = SendMessageW(CB_GETLBTEXT, index, (LPARAM)s.GetBuffer((int)len + 1));
s.ReleaseBuffer();
return len;
}
AString sa;
int len = GetLBText(index, sa);
if (len == CB_ERR)
return len;
s = GetUnicodeString(sa);
return s.Length();
}
#endif
}}

View File

@@ -14,22 +14,21 @@ namespace NControl {
class CComboBox: public CWindow
{
public:
void ResetContent()
{ SendMessage(CB_RESETCONTENT, 0, 0); }
int AddString(LPCTSTR string)
{ return SendMessage(CB_ADDSTRING, 0, (LPARAM)string); }
int SetCurSel(int index)
{ return SendMessage(CB_SETCURSEL, index, 0); }
int GetCurSel()
{ return SendMessage(CB_GETCURSEL, 0, 0); }
int GetCount()
{ return SendMessage(CB_GETCOUNT, 0, 0); }
void ResetContent() { SendMessage(CB_RESETCONTENT, 0, 0); }
LRESULT AddString(LPCTSTR string) { return SendMessage(CB_ADDSTRING, 0, (LPARAM)string); }
#ifndef _UNICODE
LRESULT AddString(LPCWSTR string);
#endif
int SetCurSel(int index) { return SendMessage(CB_SETCURSEL, index, 0); }
int GetCurSel() { return SendMessage(CB_GETCURSEL, 0, 0); }
int GetCount() { return SendMessage(CB_GETCOUNT, 0, 0); }
int GetLBTextLen(int index)
{ return SendMessage(CB_GETLBTEXTLEN, index, 0); }
int GetLBText(int index, LPTSTR string)
{ return SendMessage(CB_GETLBTEXT, index, (LPARAM)string); }
int GetLBText(int index, CSysString &string);
LRESULT GetLBTextLen(int index) { return SendMessage(CB_GETLBTEXTLEN, index, 0); }
LRESULT GetLBText(int index, LPTSTR string) { return SendMessage(CB_GETLBTEXT, index, (LPARAM)string); }
LRESULT GetLBText(int index, CSysString &s);
#ifndef _UNICODE
LRESULT GetLBText(int index, UString &s);
#endif
int SetItemData(int index, LPARAM lParam)
{ return SendMessage(CB_SETITEMDATA, index, lParam); }

View File

@@ -2,9 +2,15 @@
#include "StdAfx.h"
#ifndef _UNICODE
#include "Common/StringConvert.h"
#endif
#include "Windows/Control/Dialog.h"
extern HINSTANCE g_hInstance;
#ifndef _UNICODE
extern bool g_IsNT;
#endif
namespace NWindows {
namespace NControl {
@@ -81,8 +87,7 @@ bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow)
{
HWND aHWND = CreateDialogParam(g_hInstance,
templateName, parentWindow, DialogProcedure, LPARAM(this));
HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
if (aHWND == 0)
return false;
Attach(aHWND);
@@ -91,16 +96,50 @@ bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow)
INT_PTR CModalDialog::Create(LPCTSTR templateName, HWND parentWindow)
{
return DialogBoxParam(g_hInstance,
templateName, parentWindow, DialogProcedure, LPARAM(this));
return DialogBoxParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
}
#ifndef _UNICODE
bool CModelessDialog::Create(LPCWSTR templateName, HWND parentWindow)
{
HWND aHWND;
if (g_IsNT)
aHWND = CreateDialogParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
else
{
AString name;
LPCSTR templateNameA;
if (IS_INTRESOURCE(templateName))
templateNameA = (LPCSTR)templateName;
else
{
name = GetSystemString(templateName);
templateNameA = name;
}
aHWND = CreateDialogParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this);
}
if (aHWND == 0)
return false;
Attach(aHWND);
return true;
}
/*
INT_PTR CModalDialog::Create(LPCWSTR templateName, HWND parentWindow)
{
return DialogBoxParamW(g_hInstance,
templateName, parentWindow, DialogProcedure, LPARAM(this));
if (g_IsNT)
return DialogBoxParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
AString name;
LPCSTR templateNameA;
if (IS_INTRESOURCE(templateName))
templateNameA = (LPCSTR)templateName;
else
{
name = GetSystemString(templateName);
templateNameA = name;
}
return DialogBoxParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this);
}
*/
#endif
}}

View File

@@ -102,6 +102,9 @@ class CModelessDialog: public CDialog
{
public:
bool Create(LPCTSTR templateName, HWND parentWindow);
#ifndef _UNICODE
bool Create(LPCWSTR templateName, HWND parentWindow);
#endif
virtual void OnOK() { Destroy(); }
virtual void OnCancel() { Destroy(); }
};
@@ -110,7 +113,12 @@ class CModalDialog: public CDialog
{
public:
INT_PTR Create(LPCTSTR templateName, HWND parentWindow);
// INT_PTR Create(LPCWSTR templateName, HWND parentWindow);
INT_PTR Create(UINT resID, HWND parentWindow)
{ return Create(MAKEINTRESOURCEW(resID), parentWindow); }
#ifndef _UNICODE
INT_PTR Create(LPCWSTR templateName, HWND parentWindow);
#endif
bool End(INT_PTR result)
{ return BOOLToBool(::EndDialog(_window, result)); }
virtual void OnOK() { End(IDOK); }

View File

@@ -18,18 +18,35 @@ public:
int x, int y, int width, int height,
HWND parentWindow, HMENU idOrHMenu,
HINSTANCE instance, LPVOID createParam);
bool SetUnicodeFormat(bool fUnicode)
{ return BOOLToBool(ListView_SetUnicodeFormat(_window, BOOLToBool(fUnicode))); }
bool DeleteAllItems()
{ return BOOLToBool(ListView_DeleteAllItems(_window)); }
int InsertColumn(int columnIndex, const LVCOLUMN *columnInfo)
{ return ListView_InsertColumn(_window, columnIndex, columnInfo); }
#ifndef _UNICODE
int InsertColumn(int columnIndex, const LVCOLUMNW *columnInfo)
{ return (int)SendMessage(LVM_INSERTCOLUMNW, (WPARAM)columnIndex, (LPARAM)columnInfo); }
#endif
bool DeleteColumn(int columnIndex)
{ return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); }
int InsertItem(const LVITEM* item)
{ return ListView_InsertItem(_window, item); }
#ifndef _UNICODE
int InsertItem(const LV_ITEMW* item)
{ return (int)SendMessage(LVM_INSERTITEMW, 0, (LPARAM)item); }
#endif
bool SetItem(const LVITEM* item)
{ return BOOLToBool(ListView_SetItem(_window, item)); }
#ifndef _UNICODE
bool SetItem(const LV_ITEMW* item)
{ return BOOLToBool((BOOL)SendMessage(LVM_SETITEMW, 0, (LPARAM)item)); }
#endif
bool DeleteItem(int itemIndex)
{ return BOOLToBool(ListView_DeleteItem(_window, itemIndex)); }

View File

@@ -3,6 +3,15 @@
#include "StdAfx.h"
#include "Windows/Control/PropertyPage.h"
#include "../../Common/Vector.h"
#ifndef _UNICODE
#include "../../Common/StringConvert.h"
#endif
extern HINSTANCE g_hInstance;
#ifndef _UNICODE
extern bool g_IsNT;
#endif
namespace NWindows {
namespace NControl {
@@ -55,5 +64,102 @@ bool CPropertyPage::OnNotify(UINT controlID, LPNMHDR lParam)
return true;
}
int MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title)
{
#ifndef _UNICODE
AStringVector titles;
#endif
#ifndef _UNICODE
CRecordVector<PROPSHEETPAGEA> pagesA;
#endif
CRecordVector<PROPSHEETPAGEW> pagesW;
int i;
#ifndef _UNICODE
for (i = 0; i < pagesInfo.Size(); i++)
titles.Add(GetSystemString(pagesInfo[i].Title));
#endif
for (i = 0; i < pagesInfo.Size(); i++)
{
const CPageInfo &pageInfo = pagesInfo[i];
#ifndef _UNICODE
{
PROPSHEETPAGE page;
page.dwSize = sizeof(page);
page.dwFlags = PSP_HASHELP;
page.hInstance = g_hInstance;
page.pszTemplate = MAKEINTRESOURCE(pageInfo.ID);
page.pszIcon = NULL;
page.pfnDlgProc = NWindows::NControl::ProperyPageProcedure;
if (titles[i].IsEmpty())
page.pszTitle = NULL;
else
{
page.dwFlags |= PSP_USETITLE;
page.pszTitle = titles[i];
}
page.lParam = (LPARAM)pageInfo.Page;
page.pfnCallback = NULL;
pagesA.Add(page);
}
#endif
{
PROPSHEETPAGEW page;
page.dwSize = sizeof(page);
page.dwFlags = PSP_HASHELP;
page.hInstance = g_hInstance;
page.pszTemplate = MAKEINTRESOURCEW(pageInfo.ID);
page.pszIcon = NULL;
page.pfnDlgProc = NWindows::NControl::ProperyPageProcedure;
if (pageInfo.Title.IsEmpty())
page.pszTitle = NULL;
else
{
page.dwFlags |= PSP_USETITLE;
page.pszTitle = pageInfo.Title;
}
page.lParam = (LPARAM)pageInfo.Page;
page.pfnCallback = NULL;
pagesW.Add(page);
}
}
int res;
#ifndef _UNICODE
if (!g_IsNT)
{
PROPSHEETHEADER sheet;
sheet.dwSize = sizeof(sheet);
sheet.dwFlags = PSH_PROPSHEETPAGE;
sheet.hwndParent = hwndParent;
sheet.hInstance = g_hInstance;
AString titleA = GetSystemString(title);
sheet.pszCaption = titleA;
sheet.nPages = pagesInfo.Size();
sheet.nStartPage = 0;
sheet.ppsp = &pagesA.Front();
sheet.pfnCallback = NULL;
res = ::PropertySheetA(&sheet);
}
else
#endif
{
PROPSHEETHEADERW sheet;
sheet.dwSize = sizeof(sheet);
sheet.dwFlags = PSH_PROPSHEETPAGE;
sheet.hwndParent = hwndParent;
sheet.hInstance = g_hInstance;
sheet.pszCaption = title;
sheet.nPages = pagesInfo.Size();
sheet.nStartPage = 0;
sheet.ppsp = &pagesW.Front();
sheet.pfnCallback = NULL;
res = ::PropertySheetW(&sheet);
}
return res;
}
}}

View File

@@ -33,6 +33,14 @@ public:
virtual void OnReset(const PSHNOTIFY *aPSHNOTIFY) { OnReset(); }
};
struct CPageInfo
{
CPropertyPage *Page;
UString Title;
UINT ID;
};
int MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title);
}}

View File

@@ -18,12 +18,24 @@ public:
{ return BOOLToBool(SendMessage(SB_SETPARTS, numParts, (LPARAM)edgePostions)); }
bool SetText(LPCTSTR text)
{ return CWindow::SetText(text); }
bool SetText(int index, LPCTSTR text, UINT type)
{ return BOOLToBool(SendMessage(SB_SETTEXT, index | type, (LPARAM)text)); }
bool SetText(int index, LPCTSTR text)
{ return SetText(index, text, 0); }
void Simple(bool simple)
{ SendMessage(SB_SIMPLE, BoolToBOOL(simple), 0); }
#ifndef _UNICODE
bool Create(LONG style, LPCWSTR text, HWND hwndParent, UINT id)
{ return (_window = ::CreateStatusWindowW(style, text, hwndParent, id)) != 0; }
bool SetText(LPCWSTR text)
{ return CWindow::SetText(text); }
bool SetText(int index, LPCWSTR text, UINT type)
{ return BOOLToBool(SendMessage(SB_SETTEXTW, index | type, (LPARAM)text)); }
bool SetText(int index, LPCWSTR text)
{ return SetText(index, text, 0); }
#endif
};
}}

View File

@@ -23,6 +23,10 @@ public:
{ return HIMAGELIST(SendMessage(TB_SETIMAGELIST, listIndex, (LPARAM)imageList)); }
bool AddButton(UINT numButtons, LPTBBUTTON buttons)
{ return BOOLToBool(SendMessage(TB_ADDBUTTONS, numButtons, (LPARAM)buttons)); }
#ifndef _UNICODE
bool AddButtonW(UINT numButtons, LPTBBUTTON buttons)
{ return BOOLToBool(SendMessage(TB_ADDBUTTONSW, numButtons, (LPARAM)buttons)); }
#endif
};
}}

View File

@@ -2,11 +2,22 @@
#include "StdAfx.h"
#ifndef _UNICODE
#include "Common/StringConvert.h"
#endif
#include "Windows/Control/Window2.h"
// extern HINSTANCE g_hInstance;
#ifndef _UNICODE
extern bool g_IsNT;
#endif
namespace NWindows {
#ifndef _UNICODE
ATOM MyRegisterClass(CONST WNDCLASSW *wndClass);
#endif
namespace NControl {
static LRESULT CALLBACK WindowProcedure(HWND aHWND, UINT message,
@@ -17,12 +28,17 @@ static LRESULT CALLBACK WindowProcedure(HWND aHWND, UINT message,
tempWindow.SetUserDataLongPtr(
LONG_PTR(((LPCREATESTRUCT)lParam)->lpCreateParams));
CWindow2 *window = (CWindow2*)(tempWindow.GetUserDataLongPtr());
if (window == NULL)
return DefWindowProc(aHWND, message, wParam, lParam);
if (message == WM_NCCREATE)
if (window != NULL && message == WM_NCCREATE)
window->Attach(aHWND);
if (window == 0)
return DefWindowProc(aHWND, message, wParam, lParam);
{
#ifndef _UNICODE
if (g_IsNT)
return DefWindowProcW(aHWND, message, wParam, lParam);
else
#endif
return DefWindowProc(aHWND, message, wParam, lParam);
}
return window->OnMessage(message, wParam, lParam);
}
@@ -55,6 +71,68 @@ bool CWindow2::CreateEx(DWORD exStyle, LPCTSTR className,
idOrHMenu, instance, this);
}
#ifndef _UNICODE
bool CWindow2::CreateEx(DWORD exStyle, LPCWSTR className,
LPCWSTR windowName, DWORD style,
int x, int y, int width, int height,
HWND parentWindow, HMENU idOrHMenu,
HINSTANCE instance)
{
bool needRegister;
if(g_IsNT)
{
WNDCLASSW windowClass;
needRegister = ::GetClassInfoW(instance, className, &windowClass) == 0;
}
else
{
WNDCLASSA windowClassA;
AString classNameA;
LPCSTR classNameP;
if (IS_INTRESOURCE(className))
classNameP = (LPCSTR)className;
else
{
classNameA = GetSystemString(className);
classNameP = classNameA;
}
needRegister = ::GetClassInfoA(instance, classNameP, &windowClassA) == 0;
}
if (needRegister)
{
WNDCLASSW windowClass;
// windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.style = 0;
windowClass.lpfnWndProc = WindowProcedure;
windowClass.cbClsExtra = NULL;
windowClass.cbWndExtra = NULL;
windowClass.hInstance = instance;
windowClass.hIcon = NULL;
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = className;
if (MyRegisterClass(&windowClass) == 0)
return false;
}
return CWindow::CreateEx(exStyle, className, windowName,
style, x, y, width, height, parentWindow,
idOrHMenu, instance, this);
}
#endif
LRESULT CWindow2::DefProc(UINT message, WPARAM wParam, LPARAM lParam)
{
#ifndef _UNICODE
if (g_IsNT)
return DefWindowProcW(_window, message, wParam, lParam);
else
#endif
return DefWindowProc(_window, message, wParam, lParam);
}
LRESULT CWindow2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT result;

View File

@@ -11,12 +11,11 @@ namespace NControl {
class CWindow2: public CWindow
{
LRESULT DefProc(UINT message, WPARAM wParam, LPARAM lParam);
public:
CWindow2(HWND newWindow = NULL): CWindow(newWindow){};
virtual ~CWindow2() {};
LRESULT DefProc(UINT message, WPARAM wParam, LPARAM lParam)
{ return ::DefWindowProc(_window, message, wParam, lParam); }
bool CreateEx(DWORD exStyle, LPCTSTR className,
LPCTSTR windowName, DWORD style,
@@ -24,6 +23,14 @@ public:
HWND parentWindow, HMENU idOrHMenu,
HINSTANCE instance);
#ifndef _UNICODE
bool CreateEx(DWORD exStyle, LPCWSTR className,
LPCWSTR windowName, DWORD style,
int x, int y, int width, int height,
HWND parentWindow, HMENU idOrHMenu,
HINSTANCE instance);
#endif
virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
virtual bool OnCreate(CREATESTRUCT *createStruct) { return true; }
// virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam);