1 #include "stdafx.h"
2 #include "express_table_row.h"
3 
express_table_row()4 express_table_row::express_table_row()
5 {
6 
7 }
~express_table_row()8 express_table_row::~express_table_row()
9 {
10 
11 }
12 
GetFocusCol(CWnd * focus_owner)13 INT express_table_row::GetFocusCol(CWnd* focus_owner)
14 {
15     int col = 0;
16     CWnd* child;
17 
18     child = GetWindow(GW_CHILD);
19     while (child)
20     {
21         if (child == focus_owner)
22         {
23             break;
24         }
25 
26         col++;
27         child = child->GetWindow(GW_HWNDNEXT);
28     }
29 
30     return col;
31 }
32 
GetNextTabStopChild(CWnd * child,WPARAM keyvalue,int row_offset)33 CWnd* express_table_row::GetNextTabStopChild(CWnd *child, WPARAM keyvalue, int row_offset)
34 {
35     UINT nCmd = 0;
36     CWnd *parent = this;
37 
38     switch (keyvalue)
39     {
40     case VK_LEFT:
41     case VK_RIGHT:
42         if (keyvalue == VK_LEFT)
43         {
44             nCmd = GW_HWNDPREV;
45         }
46         else
47         {
48             nCmd = GW_HWNDNEXT;
49         }
50 
51         while (child)
52         {
53             child = child->GetWindow(nCmd);
54 
55             if (child && (child->GetStyle() & WS_TABSTOP))
56             {
57                 return child;
58             }
59         }
60         break;
61 
62     case VK_UP:
63     case VK_DOWN:
64     case VK_HOME:
65     case VK_END:
66     case VK_PRIOR:
67     case VK_NEXT:
68         if ((keyvalue == VK_UP) || (keyvalue == VK_PRIOR))
69         {
70             nCmd = GW_HWNDPREV;
71         }
72         else if ((keyvalue == VK_DOWN) || (keyvalue == VK_NEXT))
73         {
74             nCmd = GW_HWNDNEXT;
75         }
76         else if (keyvalue == VK_HOME)
77         {
78             nCmd = GW_HWNDFIRST;
79         }
80         else if(keyvalue == VK_END)
81         {
82             nCmd = GW_HWNDLAST;
83         }
84 
85         while (parent && row_offset)
86         {
87             parent = parent->GetWindow(nCmd);
88             row_offset--;
89         }
90 
91         if (parent)
92         {
93             //determine which child control should gain focus
94             int col = GetFocusCol(child);
95 
96             child = parent->GetWindow(GW_CHILD);
97 
98             while (col && child)
99             {
100                 child = child->GetWindow(GW_HWNDNEXT);
101                 col--;
102             }
103 
104             return child;
105         }
106         break;
107     }
108 
109     return NULL;
110 }
111 
AssignFocus(CWnd * child)112 void express_table_row::AssignFocus(CWnd* child)
113 {
114     if (!child)
115     {
116         return;
117     }
118 
119     child->SetFocus();
120 
121     TCHAR  class_name[MAX_PATH];
122     GetClassName(child->GetSafeHwnd(), class_name, MAX_PATH - 1);
123     if (class_name[0] == 'E'||
124         class_name[0] == 'R')
125     {
126         //"Rich Edit"
127         //"Edit"
128         CEdit* edit = (CEdit*)child;
129         edit->SetSel(0, edit->GetWindowTextLength());
130     }
131 }