GROUP.CPP
上传用户:wtrl82617
上传日期:2007-01-07
资源大小:187k
文件大小:8k
源码类别:

界面编程

开发平台:

DOS

  1. // 1993 (c) ALL RIGHTS RESERVED
  2. // AUTHOR  BY XuYongYong
  3. /* group.cpp
  4. */
  5. #include "group.h"
  6. /*************************************************************************/
  7. group_class::group_class(int ID,char *title_hotkey,
  8. int left,int top,int width,int height )
  9. : control_class(ID,title_hotkey,NORMAL ,GROUP,
  10. left,top,width,height,0,0,0)
  11. {
  12. control_num =0;
  13. pfirst_control =NULL;
  14. pcontrol_current_selected=NULL;
  15. }
  16. /*************************************************************************/
  17. group_class::~group_class()
  18. {
  19. dispose_all_controls(pfirst_control);
  20. }
  21. /*************************************************************************/
  22. void group_class::select ( )
  23. {
  24. // control_class::select();
  25. if (( pcontrol_current_selected !=NULL ) &&
  26. (!( pcontrol_current_selected->status & INVISIBLE)) )
  27. pcontrol_current_selected ->select();
  28. }
  29. /**************************************************************************/
  30. void group_class::unselect ( )
  31. {
  32. // control_class::select();
  33. if (( pcontrol_current_selected !=NULL ) &&
  34. (!( pcontrol_current_selected->status & INVISIBLE))  )
  35. pcontrol_current_selected ->unselect();
  36. }
  37. void group_class::update_control ()
  38. { Tcontrol *ptemp_control;
  39.   int i;
  40. if ( status & INVISIBLE)  return;
  41. // control_class::update_control(); recursive
  42. if (pfirst_control !=NULL ){
  43. ptemp_control =pfirst_control;
  44. for (i=0;((i<control_num) && (ptemp_control !=NULL));i++){
  45. ptemp_control ->update_control ( );
  46. ptemp_control =(Tcontrol*)ptemp_control->pright;
  47. }
  48. }
  49. select();
  50. }
  51. /*************************************************************************/
  52. void group_class::draw ()
  53. { Tcontrol *ptemp_control;
  54.   int i;
  55. if ( status & INVISIBLE)  return;
  56. control_class::draw ();
  57. if (pfirst_control !=NULL ){
  58. ptemp_control =pfirst_control;
  59. for (i=0;((i<control_num) && (ptemp_control !=NULL));i++){
  60. ptemp_control ->draw ( );
  61. ptemp_control ->control_change_value
  62. (ptemp_control->current_value );
  63. ptemp_control =(Tcontrol*)ptemp_control->pright;
  64. }
  65. }
  66. if (pcontrol_current_selected !=NULL )
  67. pcontrol_current_selected->select();
  68. }
  69. /**************************************************************************/
  70. void group_class::insert_control (Tcontrol *pcontrol_handled)
  71. {
  72. control_num ++;
  73. max_value ++;
  74. if ( pfirst_control ==NULL ) {
  75. pfirst_control=pcontrol_handled;
  76. return ;
  77. }
  78. pcontrol_handled->pright=pfirst_control->pright;
  79. pcontrol_handled->pleft =pfirst_control;
  80. pfirst_control->pright->pleft=pcontrol_handled;
  81. pfirst_control->pright=pcontrol_handled;
  82. if ( !(pcontrol_handled->status & DISABLE) &&
  83.  !(pcontrol_handled->status & INVISIBLE)  )
  84. pcontrol_current_selected =pcontrol_handled;
  85. }
  86. void group_class::setup_control ()
  87. { Tcontrol *ptemp_control;
  88.   int i;
  89. if (pfirst_control !=NULL ){
  90. ptemp_control =pfirst_control;
  91. for (i=0;((i<control_num) && (ptemp_control !=NULL));i++){
  92. ptemp_control ->setup_control ( );
  93. ptemp_control =(Tcontrol*)ptemp_control->pright;
  94. }
  95. }
  96. }
  97. /*************************************************************************/
  98. void group_class::dispose_all_controls (Tcontrol  *pcontrol_handled )
  99. {   Tcontrol *ptemp, *ptemp1;
  100. if (pcontrol_handled==NULL ) return;
  101. for (ptemp =pcontrol_handled;1; ptemp =ptemp1) {
  102. ptemp1 =(Tcontrol*)ptemp->pright ;
  103. if (ptemp  != NULL ) delete (ptemp);
  104. if (ptemp1 == pcontrol_handled ) break;
  105. }
  106. pfirst_control=NULL;
  107. pcontrol_current_selected=NULL;
  108. }
  109. /*************************************************************************/
  110. int group_class::key_pressed_handler(int key_scan_num )
  111. {
  112. // for tab and alt && etc.
  113. if (pfirst_control ==NULL ) return FALSE;
  114. if ( (key_scan_num == TABKEY ) || (key_scan_num ==SHIFT_TABKEY) )
  115. return control_tab_key_handler ( key_scan_num );
  116.   Tcontrol *ptmp, *ptmp1;
  117.   int i;
  118. // ptmp=pright;
  119. ptmp=(Tcontrol*)pcontrol_current_selected->pright;
  120. ptmp1=pcontrol_current_selected;
  121. i=current_value;
  122. for(;ptmp !=ptmp1;ptmp=(Tcontrol*)ptmp->pright, i=((i==max_value)?0 : (i+1))  ){
  123. if ( (alt_key[ toupper(ptmp->title[ptmp->hotkey])-'A'] ==key_scan_num)
  124. && (!(ptmp->status & DISABLE )) )  {
  125. if ((pcontrol_current_selected !=NULL) &&
  126. (!( pcontrol_current_selected->status & INVISIBLE)) )
  127. pcontrol_current_selected ->unselect();
  128. if (!( ptmp->status & INVISIBLE))
  129. ptmp->select();
  130. this->control_change_value (i);
  131. pcontrol_current_selected =ptmp;
  132. return TRUE;
  133. }
  134. }
  135. // normal key
  136. if (pcontrol_current_selected !=NULL )
  137. if (pcontrol_current_selected->key_pressed_handler(key_scan_num) ==TRUE )
  138. return TRUE;
  139. switch (key_scan_num) {
  140. case SHIFT_LEFT:
  141. case SHIFT_UP:
  142. case LEFTKEY:
  143. case UPKEY:
  144. case CTRL_F7:
  145. return control_tab_key_handler ( SHIFT_TABKEY );
  146. case SHIFT_RIGHT:
  147. case SHIFT_DOWN:
  148. case RIGHTKEY:
  149. case DOWNKEY:
  150. case CTRL_F8:
  151. return control_tab_key_handler ( TABKEY );
  152. default: return FALSE;
  153. }
  154. }
  155. /*************************************************************************/
  156. int group_class::control_tab_key_handler  (int key_scan_num )
  157. {
  158.   Tcontrol   *ptemp1;
  159.   int i;
  160. if (pfirst_control ==NULL ) return FALSE;
  161. if (pcontrol_current_selected ==NULL) {
  162. pcontrol_current_selected =(Tcontrol*)pfirst_control->pleft;
  163. }
  164. if ((pcontrol_current_selected !=NULL) &&
  165. (!( pcontrol_current_selected->status & INVISIBLE)) )
  166. pcontrol_current_selected ->unselect();
  167. i=((key_scan_num==TABKEY)?current_value+1:current_value-1);
  168. if (i<0)  i=max_value-1;
  169. if (i>max_value-1) i=0;
  170. for(ptemp1 =(Tcontrol*) ( (key_scan_num==TABKEY) ? pcontrol_current_selected-> pright
  171.   : pcontrol_current_selected-> pleft
  172.  );
  173. ((ptemp1 !=this) && (ptemp1->status & DISABLE ));
  174. ptemp1 =(Tcontrol*) ( (key_scan_num==TABKEY) ? ptemp1 ->pright
  175.   : ptemp1 ->pleft
  176.  )
  177.    )  {
  178. i=((key_scan_num ==TABKEY)?(i+1):(i-1));
  179. if (i<0)  i=max_value-1;
  180. if (i>max_value-1) i=0;
  181.    }
  182. if ( (ptemp1 !=this ) && (!( ptemp1->status & INVISIBLE)) )
  183. ptemp1->select ( );
  184. this->control_change_value (i);
  185. pcontrol_current_selected =ptemp1;
  186. return TRUE;
  187. }
  188. /*************************************************************************/
  189. int group_class::msg_handler (MSG& message )
  190. {
  191.   int ret_val;
  192. // if ( (ret_val= control_class::msg_handler(message))!=FALSE)
  193. // return ret_val;
  194. switch (message.Action){
  195. case MouseLButtonDownMSG:
  196.   Tcontrol *ptmp,*ptmp1;
  197. if (pfirst_control==NULL) return FALSE;
  198. if (pcontrol_current_selected==NULL) ptmp1=pfirst_control;
  199. else ptmp1=pcontrol_current_selected;
  200.   int i; i=current_value;
  201. if ( (ptmp=(Tcontrol*)ptmp1->get_object_thru_point (win_mouse_x,win_mouse_y))==NULL) break;
  202. if (!PtInRect (win_mouse_x,win_mouse_y, ptmp->bounds)) return FALSE;
  203. i=i+ptmp1->step;
  204. if (ptmp==pcontrol_current_selected) break; //to current control
  205. if ((pcontrol_current_selected !=NULL) &&
  206. (!( pcontrol_current_selected->status & INVISIBLE)) )
  207. pcontrol_current_selected ->unselect();
  208. if (!( ptmp->status & INVISIBLE))
  209. ptmp->select();
  210. if (i>=max_value) i =i-max_value;
  211. this->control_change_value (i); //Note !!!! seem i;
  212. pcontrol_current_selected =ptmp;
  213. return TRUE;
  214. // default:return  control_class::msg_handler(message);
  215. }
  216. if (pcontrol_current_selected !=NULL )
  217. return pcontrol_current_selected->msg_handler(message);
  218. else return  control_class::msg_handler(message);
  219. // I don't know whether this is valid
  220. }
  221. /*************************************************************************/
  222. int group_class::control_change_value (int new_value )
  223. {   if (control_class::control_change_value(new_value)==TRUE)
  224. return TRUE;
  225. current_value =new_value;
  226. thequeue.SendMessage(ID,GroupValueChangedMSG,this);
  227. return TRUE;
  228. }