Previous 15994 Revisions Next

r1452 Saturday 29th December, 2007 at 19:05:46 UTC by Nathan Woods
[Windows] Another try at fixing the input dialog
[src/mess/osd/windows]dialog.c

src/mess/osd/windows/dialog.c
r1451r1452
2929
3030//============================================================
3131
32#define SEQWM_SETFOCUS   (WM_APP + 0)
33#define SEQWM_KILLFOCUS   (WM_APP + 1)
34
3235enum
3336{
3437   TRIGGER_INITDIALOG   = 1,
r1451r1452
8083   void *notify_param;
8184};
8285
86enum _seqselect_state
87{
88   SEQSELECT_STATE_NOT_POLLING,
89   SEQSELECT_STATE_POLLING,
90   SEQSELECT_STATE_POLLING_COMPLETE
91};
92typedef enum _seqselect_state seqselect_state;
93
8394// this is the structure that gets associated with each input_seq edit box
8495typedef struct _seqselect_info seqselect_info;
8596struct _seqselect_info
r1451r1452
8798   WNDPROC oldwndproc;
8899   input_seq *code;      // pointer to the input_seq
89100   input_seq newcode;      // the new input_seq; committed to *code when we are done
90   UINT_PTR timer;
91101   WORD pos;
92102   BOOL is_analog;
93   int start_poll;
103   seqselect_state poll_state;
94104};
95105
96106
r1451r1452
126136#define FONT_SIZE            8
127137#define FONT_FACE            L"Arial"
128138
129#define TIMER_ID            0xdeadbeef
130
131139#define SCROLL_DELTA_LINE      10
132140#define SCROLL_DELTA_PAGE      100
133141
r1451r1452
10511059{
10521060   seqselect_info *stuff;
10531061   astring *seqstring;
1062   char buffer[128];
10541063
1064   // the basics
1065   stuff = get_seqselect_info(editwnd);
1066   if (stuff == NULL)
1067      return;   // this should not happen - need to fix this
1068
1069   // retrieve the seq name
10551070   seqstring = astring_alloc();
1056
1057   stuff = get_seqselect_info(editwnd);
10581071   input_seq_name(seqstring, &stuff->newcode);
1059   win_set_window_text_utf8(editwnd, astring_c(seqstring));
10601072
1073   // change the text - avoid calls to SetWindowText() if we can
1074   win_get_window_text_utf8(editwnd, buffer, ARRAY_LENGTH(buffer));
1075   if (strcmp(buffer, astring_c(seqstring)))
1076      win_set_window_text_utf8(editwnd, astring_c(seqstring));
1077
1078   // reset the selection
10611079   if (GetFocus() == editwnd)
10621080      SendMessage(editwnd, EM_SETSEL, 0, -1);
10631081
r1451r1452
10671085
10681086
10691087//============================================================
1070//   seqselect_read_from_main_thread
1088//   seqselect_start_read_from_main_thread
10711089//============================================================
10721090
1073static void seqselect_read_from_main_thread(void *param)
1091static void seqselect_start_read_from_main_thread(void *param)
10741092{
10751093   seqselect_info *stuff;
10761094   HWND editwnd;
10771095   int ret;
10781096   win_window_info fake_window_info;
10791097   win_window_info *old_window_list;
1098   int pause_count;
10801099
10811100   // get the basics
10821101   editwnd = (HWND) param;
10831102   stuff = get_seqselect_info(editwnd);
10841103
1104   // are we currently polling?  if so bail out
1105   if (stuff->poll_state != SEQSELECT_STATE_NOT_POLLING)
1106      return;
1107
1108   // change the state
1109   stuff->poll_state = SEQSELECT_STATE_POLLING;
1110
10851111   // the Win32 OSD code thinks that we are paused, we need to temporarily
10861112   // unpause ourselves or else we will block
1087   winwindow_ui_pause_from_main_thread(FALSE);
1113   pause_count = 0;
1114   while(mame_is_paused(Machine) && !winwindow_ui_is_paused())
1115   {
1116      winwindow_ui_pause_from_main_thread(FALSE);
1117      pause_count++;
1118   }
10881119
10891120   // butt ugly hack so that we accept focus
10901121   old_window_list = win_window_list;
r1451r1452
10921123   fake_window_info.hwnd = GetFocus();
10931124   win_window_list = &fake_window_info;
10941125
1095   // start polling if we are told to
1096   if (stuff->start_poll)
1126   // start the polling
1127   input_seq_poll_start(stuff->is_analog ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, NULL);
1128
1129   while(stuff->poll_state == SEQSELECT_STATE_POLLING)
10971130   {
1098      input_seq_poll_start(stuff->is_analog ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, NULL);
1099      stuff->start_poll = FALSE;
1131      // poll
1132      ret = input_seq_poll(&stuff->newcode);
1133      seqselect_settext(editwnd);
11001134   }
11011135
1102   // poll
1103   ret = input_seq_poll(&stuff->newcode);
1104   seqselect_settext(editwnd);
1105
11061136   // clean up after hack
11071137   win_window_list = old_window_list;
11081138
1139   // we are no longer polling
1140   stuff->poll_state = SEQSELECT_STATE_NOT_POLLING;
1141
11091142   // repause the OSD code
1110   winwindow_ui_pause_from_main_thread(TRUE);
1143   while(pause_count--)
1144      winwindow_ui_pause_from_main_thread(TRUE);
11111145}
11121146
11131147
11141148
11151149//============================================================
1150//   seqselect_stop_read_from_main_thread
1151//============================================================
1152
1153static void seqselect_stop_read_from_main_thread(void *param)
1154{
1155   HWND editwnd;
1156   seqselect_info *stuff;
1157
1158   // get the basics
1159   editwnd = (HWND) param;
1160   stuff = get_seqselect_info(editwnd);
1161   
1162   // stop the read
1163   if (stuff->poll_state == SEQSELECT_STATE_POLLING)
1164      stuff->poll_state = SEQSELECT_STATE_POLLING_COMPLETE;
1165}
1166
1167
1168
1169//============================================================
11161170//   seqselect_wndproc
11171171//============================================================
11181172
r1451r1452
11241178
11251179   stuff = get_seqselect_info(editwnd);
11261180
1127   switch(msg) {
1128   case WM_KEYDOWN:
1129   case WM_SYSKEYDOWN:
1130   case WM_CHAR:
1131   case WM_KEYUP:
1132   case WM_SYSKEYUP:
1133      result = 1;
1134      call_baseclass = FALSE;
1135      break;
1136
1137   case WM_TIMER:
1138      if (wparam == TIMER_ID)
1139      {
1140         winwindow_ui_exec_on_main_thread(seqselect_read_from_main_thread, (void *) editwnd);
1141         result = 0;
1181   switch(msg)
1182   {
1183      case WM_KEYDOWN:
1184      case WM_SYSKEYDOWN:
1185      case WM_CHAR:
1186      case WM_KEYUP:
1187      case WM_SYSKEYUP:
1188         result = 1;
11421189         call_baseclass = FALSE;
1143      }
1144      break;
1190         break;
11451191
1146   case WM_SETFOCUS:
1147   case WM_KILLFOCUS:
1148      // unselect the current seq; if appropriate
1149      if (stuff->timer)
1150      {
1151         KillTimer(editwnd, stuff->timer);
1152         stuff->timer = 0;
1153      }
1192      case WM_SETFOCUS:
1193         PostMessage(editwnd, SEQWM_SETFOCUS, 0, 0);
1194         break;
11541195
1155      if (msg == WM_SETFOCUS)
1156      {
1157         // we are selecting a seq; begin a timer
1158         stuff->start_poll = TRUE;
1159         stuff->timer = SetTimer(editwnd, TIMER_ID, 100, (TIMERPROC) NULL);
1160      }
1161      break;
1196      case WM_KILLFOCUS:
1197         PostMessage(editwnd, SEQWM_KILLFOCUS, 0, 0);
1198         break;
11621199
1163   case WM_LBUTTONDOWN:
1164   case WM_RBUTTONDOWN:
1165      SetFocus(editwnd);
1166      SendMessage(editwnd, EM_SETSEL, 0, -1);
1167      call_baseclass = FALSE;
1168      result = 0;
1169      break;
1200      case SEQWM_SETFOCUS:
1201         // if we receive the focus, we should start a polling loop
1202         winwindow_ui_exec_on_main_thread(seqselect_start_read_from_main_thread, (void *) editwnd);
1203         break;
1204
1205      case SEQWM_KILLFOCUS:
1206         // when we abort the focus, end any current polling loop
1207         winwindow_ui_exec_on_main_thread(seqselect_stop_read_from_main_thread, (void *) editwnd);
1208         break;
1209
1210      case WM_LBUTTONDOWN:
1211      case WM_RBUTTONDOWN:
1212         SetFocus(editwnd);
1213         SendMessage(editwnd, EM_SETSEL, 0, -1);
1214         call_baseclass = FALSE;
1215         result = 0;
1216         break;
11701217   }
11711218
11721219   if (call_baseclass)
r1451r1452
12691316   memset(stuff, 0, sizeof(*stuff));
12701317   stuff->code = code;
12711318   stuff->pos = di->item_count;
1272   stuff->timer = 0;
12731319   stuff->is_analog = is_analog;
12741320   if (dialog_add_trigger(di, di->item_count, TRIGGER_INITDIALOG, 0, seqselect_setup, di->item_count, (LPARAM) stuff, NULL, NULL))
12751321      return 1;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team