[sword-svn] r189 - in trunk/src/SwordReader_GUI: . SRFramework
dtrotzjr at crosswire.org
dtrotzjr at crosswire.org
Sat Jan 3 13:07:04 MST 2009
Author: dtrotzjr
Date: 2009-01-03 13:07:04 -0700 (Sat, 03 Jan 2009)
New Revision: 189
Modified:
trunk/src/SwordReader_GUI/SRFramework/SRComboBox.cpp
trunk/src/SwordReader_GUI/SRFramework/SRComboBox.h
trunk/src/SwordReader_GUI/SRFramework/SRWnd.h
trunk/src/SwordReader_GUI/SRLexiView.h
trunk/src/SwordReader_GUI/SRLexiWidget.cpp
trunk/src/SwordReader_GUI/SRLexiWidget.h
Log:
More dictionary support. Can now look up any word in the dictionary. Not able to change dictionaries just yet.
Modified: trunk/src/SwordReader_GUI/SRFramework/SRComboBox.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRComboBox.cpp 2009-01-03 04:05:48 UTC (rev 188)
+++ trunk/src/SwordReader_GUI/SRFramework/SRComboBox.cpp 2009-01-03 20:07:04 UTC (rev 189)
@@ -30,13 +30,35 @@
WCString SRComboBox::GetText()
{
TCHAR *strQuery = NULL;
+ WCString wcsQuery;
+
INT nQueryLen = ::SendMessage(m_hWnd, WM_GETTEXTLENGTH, NULL, NULL) + 1;
strQuery = new TCHAR[nQueryLen];
::SendMessage(m_hWnd,WM_GETTEXT,(WPARAM)nQueryLen,(LPARAM)strQuery);
strQuery[nQueryLen - 1] = 0; // in case the buffer was exceeded
- return strQuery;
+
+ wcsQuery = strQuery;
+ delete [] strQuery;
+
+ return wcsQuery;
}
+WCString SRComboBox::GetItemAt(INT nItemIndex)
+{
+ TCHAR *strQuery = NULL;
+ WCString wcsQuery;
+
+ INT nQueryLen = ::SendMessage(m_hWnd, CB_GETLBTEXTLEN, (WPARAM)nItemIndex, NULL) + 1;
+ strQuery = new TCHAR[nQueryLen];
+ ::SendMessage(m_hWnd,CB_GETLBTEXT,(WPARAM)nItemIndex,(LPARAM)strQuery);
+ strQuery[nQueryLen - 1] = 0; // in case the buffer was exceeded
+
+ wcsQuery = strQuery;
+ delete [] strQuery;
+
+ return wcsQuery;
+}
+
VOID SRComboBox::Clear()
{
::SendMessage (m_hWnd, CB_RESETCONTENT,0,0);
@@ -64,10 +86,20 @@
INT SRComboBox::SelectItem(const WCString &wcsItem)
{
- return ::SendMessage (m_hWnd, CB_FINDSTRING, 0, (LPARAM)(LPCTSTR)wcsItem.w_str());
+ return ::SendMessage (m_hWnd, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)wcsItem.w_str());
}
+INT SRComboBox::SetCurSel(INT nItemIndex)
+{
+ return ::SendMessage(m_hWnd, CB_SETCURSEL, (WPARAM)nItemIndex, 0);
+}
+
INT SRComboBox::GetCurSel()
{
return ::SendMessage (m_hWnd, CB_GETCURSEL, 0,0);
+}
+
+BOOL SRComboBox::SetText(const WCString &text)
+{
+ return ::SendMessage(m_hWnd, WM_SETTEXT, NULL, (LPARAM)text.w_str());
}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRFramework/SRComboBox.h
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRComboBox.h 2009-01-03 04:05:48 UTC (rev 188)
+++ trunk/src/SwordReader_GUI/SRFramework/SRComboBox.h 2009-01-03 20:07:04 UTC (rev 189)
@@ -20,7 +20,10 @@
INT DeleteItem(INT nItemIndex);
INT FindItem(const WCString &wcsItem);
INT SelectItem(const WCString &wcsItem);
+ INT SetCurSel(INT nItemIndex);
INT GetCurSel();
+ BOOL SetText(const WCString &text);
+ WCString GetItemAt(INT nItemIndex);
};
}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRFramework/SRWnd.h
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRWnd.h 2009-01-03 04:05:48 UTC (rev 188)
+++ trunk/src/SwordReader_GUI/SRFramework/SRWnd.h 2009-01-03 20:07:04 UTC (rev 189)
@@ -7,14 +7,14 @@
namespace SRFramework
{
-
-
class SRWnd
{
public:
SRWnd();
virtual ~SRWnd(void);
+
+ BOOL IshWnd(HWND hWnd) { return hWnd == m_hWnd; }
//! The actual call back function for this window.
/*! This only acts as a mediator between the callback function we really
Modified: trunk/src/SwordReader_GUI/SRLexiView.h
===================================================================
--- trunk/src/SwordReader_GUI/SRLexiView.h 2009-01-03 04:05:48 UTC (rev 188)
+++ trunk/src/SwordReader_GUI/SRLexiView.h 2009-01-03 20:07:04 UTC (rev 189)
@@ -19,10 +19,11 @@
VOID SetModule(SWModule *pModule);
VOID SetSwordReady() { m_fSwordInit = TRUE; }
VOID RefreshScreen(BOOL fReloadText);
+ SWModule *GetModule() { return m_pModule; }
+ const SWKey &GetKey() { return *m_pModule->getKey(); }
+
BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
VOID Show();
- SWModule *GetModule() { return m_pModule; }
- const SWKey &GetKey() { return *m_pModule->getKey(); }
private:
VOID LoadTextView();
Modified: trunk/src/SwordReader_GUI/SRLexiWidget.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRLexiWidget.cpp 2009-01-03 04:05:48 UTC (rev 188)
+++ trunk/src/SwordReader_GUI/SRLexiWidget.cpp 2009-01-03 20:07:04 UTC (rev 189)
@@ -67,9 +67,10 @@
RECT lblRect = m_rect;
RECT cmbRect = m_rect;
RECT viewRect = m_rect;
+ lblRect.top = 4;
+ lblRect.left = 4;
lblRect.right = 60;
cmbRect.left = 60;
- cmbRect.bottom = 60;
lblRect.bottom = 20;
viewRect.top = 20;
@@ -90,20 +91,40 @@
return TRUE;
}
-
+/*
+ Partially fills the ComboBox drop down with entries based upon
+ the current text.
+ */
VOID SRLexiWidget::FillDictEntries()
{
+ INT nCount = 0;
+ INT nMaxCount = 10;
+ INT nCurSel = 0;
+
if(!m_cmbDictEntry)
return;
SWModule *pModule = m_viewLexi->GetModule();
if(!pModule)
return;
- pModule->setKey("");
+
+ pModule->setKey(m_wcsCurEntry.c_str());
pModule->Error();
- while(!pModule->Error()){
+ // Back up halfway or as far as we can
+ for(nCount = 0; nCount < nMaxCount/2; nCount++){
+ (*pModule)--;
+ if(pModule->Error())
+ break;
+ }
+ nCurSel = nCount;
+
+ m_cmbDictEntry->Clear();
+ for(nCount = 0; nCount < nMaxCount; nCount++){
m_cmbDictEntry->AddItem(pModule->getKeyText());
(*pModule)++;
+ if(pModule->Error())
+ break;
}
+ m_cmbDictEntry->SetCurSel(nCurSel);
}
const SWKey &SRLexiWidget::GetKey()
@@ -148,6 +169,67 @@
VOID SRLexiWidget::SetKey(const sword::StrKey &key)
{
- if(m_viewLexi)
+ if(m_viewLexi){
m_viewLexi->SetKey(key);
+ m_wcsCurEntry = key.getText();
+ m_cmbDictEntry->SetText(m_wcsCurEntry);
+ }
}
+
+BOOL SRLexiWidget::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
+{
+ BOOL retval = FALSE;
+ if(m_viewLexi){
+ retval = m_viewLexi->OnKeyDown(nChar, nRepCnt, nFlags);
+ if(m_cmbDictEntry){
+ m_wcsCurEntry = m_viewLexi->GetKey().getText();
+ m_cmbDictEntry->SetText(m_wcsCurEntry);
+ }
+ }
+ return retval;
+}
+
+
+BOOL SRLexiWidget::OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl)
+{
+ INT nCurSel = -1;
+
+ if(m_cmbDictEntry && m_cmbDictEntry->IshWnd(hWndCtl)){
+ switch(wNotifyCode) {
+ case CBN_ERRSPACE:
+ return FALSE;
+ case CBN_SELCHANGE:
+ nCurSel = m_cmbDictEntry->GetCurSel();
+ m_wcsCurEntry = m_cmbDictEntry->GetItemAt(nCurSel);
+ m_cmbDictEntry->SetText(m_wcsCurEntry);
+ m_viewLexi->SetEntry(m_wcsCurEntry);
+ break;
+ case CBN_DBLCLK:
+ return FALSE;
+ case CBN_SETFOCUS:
+ return FALSE;
+ case CBN_KILLFOCUS:
+ return FALSE;
+ case CBN_EDITCHANGE:
+ m_wcsCurEntry = m_cmbDictEntry->GetText();
+ m_viewLexi->SetEntry(m_wcsCurEntry);
+ break;
+ case CBN_EDITUPDATE:
+ return FALSE;
+ case CBN_DROPDOWN:
+ FillDictEntries();
+ break;
+ case CBN_CLOSEUP:
+ return FALSE;
+ case CBN_SELENDOK:
+ m_wcsCurEntry = m_cmbDictEntry->GetText();
+ m_viewLexi->SetEntry(m_wcsCurEntry);
+ break;
+ case CBN_SELENDCANCEL:
+ return FALSE;
+ default:
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRLexiWidget.h
===================================================================
--- trunk/src/SwordReader_GUI/SRLexiWidget.h 2009-01-03 04:05:48 UTC (rev 188)
+++ trunk/src/SwordReader_GUI/SRLexiWidget.h 2009-01-03 20:07:04 UTC (rev 189)
@@ -24,10 +24,14 @@
VOID RefreshWindow();
VOID RefreshScreen(BOOL fReloadText);
VOID FillDictEntries();
+ BOOL OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl);
+
+ BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
private:
static BOOL s_fRegistered;
SRComboBox *m_cmbDictEntry;
SRLabel *m_lblEntry;
SRLexiView *m_viewLexi;
SWKey m_keyDummy;
+ WCString m_wcsCurEntry;
};
More information about the sword-cvs
mailing list