first impl (needs extending)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10861 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2001-07-06 16:10:17 +00:00
parent 98363307d3
commit ffc93a32d8
3 changed files with 94 additions and 63 deletions

View File

@@ -23,7 +23,6 @@ class WXDLLEXPORT wxAcceleratorTable: public wxObject
DECLARE_DYNAMIC_CLASS(wxAcceleratorTable) DECLARE_DYNAMIC_CLASS(wxAcceleratorTable)
public: public:
wxAcceleratorTable(); wxAcceleratorTable();
wxAcceleratorTable(const wxString& resource); // Load from .rc resource
wxAcceleratorTable(int n, wxAcceleratorEntry entries[]); // Load from array wxAcceleratorTable(int n, wxAcceleratorEntry entries[]); // Load from array
// Copy constructors // Copy constructors
@@ -37,6 +36,8 @@ public:
inline bool operator != (const wxAcceleratorTable& accel) { return m_refData != accel.m_refData; } inline bool operator != (const wxAcceleratorTable& accel) { return m_refData != accel.m_refData; }
bool Ok() const; bool Ok() const;
int GetCommand( wxKeyEvent &event );
}; };
WXDLLEXPORT_DATA(extern wxAcceleratorTable) wxNullAcceleratorTable; WXDLLEXPORT_DATA(extern wxAcceleratorTable) wxNullAcceleratorTable;

View File

@@ -21,6 +21,18 @@
IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
#endif #endif
// ----------------------------------------------------------------------------
// wxAccelList: a list of wxAcceleratorEntries
// ----------------------------------------------------------------------------
WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxAccelList);
// ----------------------------------------------------------------------------
// wxAccelRefData: the data used by wxAcceleratorTable
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
{ {
friend class WXDLLEXPORT wxAcceleratorTable; friend class WXDLLEXPORT wxAcceleratorTable;
@@ -28,32 +40,19 @@ public:
wxAcceleratorRefData(); wxAcceleratorRefData();
~wxAcceleratorRefData(); ~wxAcceleratorRefData();
/* TODO: implementation wxAccelList m_accels;
inline HACCEL GetHACCEL() const { return m_hAccel; }
protected:
HACCEL m_hAccel;
*/
}; };
#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
wxAcceleratorRefData::wxAcceleratorRefData() wxAcceleratorRefData::wxAcceleratorRefData()
{ {
// TODO m_accels.DeleteContents( TRUE );
/*
HACCEL m_hAccel;
*/
} }
wxAcceleratorRefData::~wxAcceleratorRefData() wxAcceleratorRefData::~wxAcceleratorRefData()
{ {
/* m_accels.DeleteContents( TRUE );
if (m_hAccel)
{
DestroyAcceleratorTable((HACCEL) m_hAccel);
}
m_hAccel = 0 ;
*/
} }
wxAcceleratorTable::wxAcceleratorTable() wxAcceleratorTable::wxAcceleratorTable()
@@ -65,29 +64,45 @@ wxAcceleratorTable::~wxAcceleratorTable()
{ {
} }
// Load from .rc resource
wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
{
m_refData = new wxAcceleratorRefData;
/* TODO: load acelerator from resource, if appropriate for your platform
M_ACCELDATA->m_hAccel = hAccel;
M_ACCELDATA->m_ok = (hAccel != 0);
*/
}
// Create from an array // Create from an array
wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[])
{ {
m_refData = new wxAcceleratorRefData; m_refData = new wxAcceleratorRefData;
/* TODO: create table from entries for (int i = 0; i < n; i++)
*/ {
int flag = entries[i].GetFlags();
int keycode = entries[i].GetKeyCode();
int command = entries[i].GetCommand();
if ((keycode >= (int)'a') && (keycode <= (int)'z')) keycode = (int)toupper( (char)keycode );
M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
}
} }
bool wxAcceleratorTable::Ok() const bool wxAcceleratorTable::Ok() const
{ {
// TODO return (m_refData != NULL);
return FALSE;
} }
int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
{
if (!Ok()) return -1;
wxNode *node = M_ACCELDATA->m_accels.First();
while (node)
{
wxAcceleratorEntry *entry = (wxAcceleratorEntry*)node->Data();
if ((event.m_keyCode == entry->GetKeyCode()) &&
(((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) &&
(((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) &&
(((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown() || event.MetaDown()))
{
return entry->GetCommand();
}
node = node->Next();
}
return -1;
}

View File

@@ -21,6 +21,18 @@
IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
#endif #endif
// ----------------------------------------------------------------------------
// wxAccelList: a list of wxAcceleratorEntries
// ----------------------------------------------------------------------------
WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxAccelList);
// ----------------------------------------------------------------------------
// wxAccelRefData: the data used by wxAcceleratorTable
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
{ {
friend class WXDLLEXPORT wxAcceleratorTable; friend class WXDLLEXPORT wxAcceleratorTable;
@@ -28,32 +40,19 @@ public:
wxAcceleratorRefData(); wxAcceleratorRefData();
~wxAcceleratorRefData(); ~wxAcceleratorRefData();
/* TODO: implementation wxAccelList m_accels;
inline HACCEL GetHACCEL() const { return m_hAccel; }
protected:
HACCEL m_hAccel;
*/
}; };
#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
wxAcceleratorRefData::wxAcceleratorRefData() wxAcceleratorRefData::wxAcceleratorRefData()
{ {
// TODO m_accels.DeleteContents( TRUE );
/*
HACCEL m_hAccel;
*/
} }
wxAcceleratorRefData::~wxAcceleratorRefData() wxAcceleratorRefData::~wxAcceleratorRefData()
{ {
/* m_accels.DeleteContents( TRUE );
if (m_hAccel)
{
DestroyAcceleratorTable((HACCEL) m_hAccel);
}
m_hAccel = 0 ;
*/
} }
wxAcceleratorTable::wxAcceleratorTable() wxAcceleratorTable::wxAcceleratorTable()
@@ -65,29 +64,45 @@ wxAcceleratorTable::~wxAcceleratorTable()
{ {
} }
// Load from .rc resource
wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
{
m_refData = new wxAcceleratorRefData;
/* TODO: load acelerator from resource, if appropriate for your platform
M_ACCELDATA->m_hAccel = hAccel;
M_ACCELDATA->m_ok = (hAccel != 0);
*/
}
// Create from an array // Create from an array
wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[])
{ {
m_refData = new wxAcceleratorRefData; m_refData = new wxAcceleratorRefData;
/* TODO: create table from entries for (int i = 0; i < n; i++)
*/ {
int flag = entries[i].GetFlags();
int keycode = entries[i].GetKeyCode();
int command = entries[i].GetCommand();
if ((keycode >= (int)'a') && (keycode <= (int)'z')) keycode = (int)toupper( (char)keycode );
M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
}
} }
bool wxAcceleratorTable::Ok() const bool wxAcceleratorTable::Ok() const
{ {
// TODO return (m_refData != NULL);
return FALSE;
} }
int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
{
if (!Ok()) return -1;
wxNode *node = M_ACCELDATA->m_accels.First();
while (node)
{
wxAcceleratorEntry *entry = (wxAcceleratorEntry*)node->Data();
if ((event.m_keyCode == entry->GetKeyCode()) &&
(((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) &&
(((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) &&
(((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown() || event.MetaDown()))
{
return entry->GetCommand();
}
node = node->Next();
}
return -1;
}