Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIWin32.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4UIWin32.cc 66892 2013-01-17 10:57:59Z gunter $
28 //
29 // G.Barrand
30 
31 //#define DEBUG
32 
33 #ifdef G4UI_BUILD_WIN32_SESSION
34 
35 // this :
36 #include "G4UIWin32.hh"
37 
38 #include <string.h>
39 
40 #include <windows.h>
41 #include <windowsx.h>
42 #include <wingdi.h>
43 
44 #include <strstream>
45 
46 #include "G4UImanager.hh"
47 #include "G4StateManager.hh"
48 #include "G4UIcommandTree.hh"
49 #include "G4UIcommandStatus.hh"
50 #include "G4Win32.hh"
51 
52 #define TEXT_MAX_LINES 300
53 
54 class TextBuffer
55 {
56 public:
57  TextBuffer();
58  ~TextBuffer();
59 
60  int GetNumberOfLines () { return linei;}
61  void SetHeightOfPage (int a_height) { heightOfPage = a_height; }
62  void SetEndOfPage (int a_value);
63  int GetEndOfPage () { return endOfPage; }
64 
65  void IncrementEndOfPage ();
66  void DecrementEndOfPage ();
67  void JumpDownEndOfPage ();
68  void JumpUpEndOfPage ();
69  G4bool AppendString (char* a_string);
70  void Draw (HDC a_hdc,RECT* a_rect);
71 
72 private:
73  G4String* lines;
74  int linen;
75  int linei;
76  int endOfPage,heightOfPage;
77  char spaces[256];
78 };
79 
80 TextBuffer::TextBuffer()
81  : linei(0),linen(TEXT_MAX_LINES),endOfPage(0),heightOfPage(12)
82 {
83  lines = new G4String[linen];
84  for(int count=0;count<256;count++) spaces[count] = ' ';
85 }
86 
87 TextBuffer::~TextBuffer()
88 {
89  delete [] lines;
90 }
91 
92 void TextBuffer::SetEndOfPage (int a_value)
93 {
94  if( (a_value<0) || (a_value>=linei)) {
95  endOfPage = linei-1;
96  } else {
97  endOfPage = a_value;
98  }
99 }
100 
101 void TextBuffer::IncrementEndOfPage ()
102 {
103  endOfPage++;
104  if(endOfPage>=linei) endOfPage = linei-1;
105 }
106 
107 void TextBuffer::DecrementEndOfPage ()
108 {
109  endOfPage--;
110  if(endOfPage<0) endOfPage = 0;
111 }
112 
113 void TextBuffer::JumpDownEndOfPage ()
114 {
115  endOfPage += heightOfPage;
116  if(endOfPage>=linei) endOfPage = linei-1;
117 }
118 
119 void TextBuffer::JumpUpEndOfPage ()
120 {
121  endOfPage -= heightOfPage;
122  if(endOfPage<0) endOfPage = 0;
123 }
124 
125 G4bool TextBuffer::AppendString (char* a_string)
126 {
127  G4bool value = false;
128  if( (a_string==NULL) || (a_string[0]=='\0') ) return value;
129  int length = strlen(a_string);
130  if(a_string[length-1]=='\n') {
131  lines[linei] += a_string;
132  lines[linei] = lines[linei].strip(G4String::trailing,'\n');
133  linei++;
134  value = true;
135  } else {
136  lines[linei] += a_string;
137  }
138  if(linei>=linen) {
139  for(int count=0;count<linen;count++) {
140  lines[count] = "";
141  }
142  linei = 0;
143  }
144  if(value==true) endOfPage = linei-1;
145  return value;
146 }
147 
148 void TextBuffer::Draw (HDC a_hdc,RECT* a_rect)
149 {
150  TEXTMETRIC tm;
151  GetTextMetrics (a_hdc,&tm);
152  short charWidth = (short)tm.tmAveCharWidth;
153  short charHeight = (short)(tm.tmHeight + tm.tmExternalLeading);
154  for(int row=0;row<heightOfPage;row++) {
155  int rowi = endOfPage - row;
156  short y = (short)(a_rect->bottom - charHeight * (row + 1));
157  if((rowi>=0)&&(rowi<linei)) {
158  TextOut (a_hdc,0,y,(char*)spaces,256); //Clear text background first.
159  const char* string = lines[rowi].data();
160  if(string!=NULL) {
161  TextOut (a_hdc,0,y,(char*)string,strlen((char*)string));
162  }
163  }
164  }
165 }
166 
167 /***************************************************************************/
168 static char mainClassName[] = "G4UIWin32";
169 static char textClassName[] = "G4UIWin32/Text";
170 static G4bool exitSession = true;
171 static G4bool exitPause = true;
172 static G4bool exitHelp = true;
173 static G4UIsession* tmpSession = NULL;
174 
175 static WNDPROC oldEditWindowProc;
176 static G4bool ConvertStringToInt(const char*,int&);
177 
178 static int actionIdentifier = 0;
179 
180 /***************************************************************************/
181 G4UIWin32::G4UIWin32 (
182 )
183 :mainWindow(NULL)
184 ,textWindow(NULL)
185 ,editWindow(NULL)
186 ,menuBar(NULL)
187 ,textBuffer(NULL)
188 ,textCols(80)
189 ,textRows(12)
190 ,fHelp(false)
191 ,fHelpChoice(0)
192 ,fHistoryPos(-1)
193 /***************************************************************************/
194 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
195 {
197  if(UI!=NULL) UI->SetSession(this);
198 
199  interactorManager = G4Win32::getInstance ();
200  static G4bool Done = FALSE;
201  if(Done==FALSE) {
202  WNDCLASS wc;
203  wc.style = CS_HREDRAW | CS_VREDRAW;
204  wc.lpfnWndProc = (WNDPROC)G4UIWin32::MainWindowProc;
205  wc.cbClsExtra = 0;
206  wc.cbWndExtra = 0;
207  wc.hInstance = ::GetModuleHandle(NULL);
208  wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
209  wc.hCursor = LoadCursor(NULL,IDC_ARROW);
210  wc.hbrBackground = GetStockBrush(WHITE_BRUSH);
211  wc.lpszMenuName = mainClassName;
212  wc.lpszClassName = mainClassName;
213  ::RegisterClass (&wc);
214 
215  wc.style = CS_HREDRAW | CS_VREDRAW;
216  wc.lpfnWndProc = (WNDPROC)G4UIWin32::TextWindowProc;
217  wc.cbClsExtra = 0;
218  wc.cbWndExtra = 0;
219  wc.hInstance = ::GetModuleHandle(NULL);
220  wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
221  wc.hCursor = LoadCursor(NULL,IDC_ARROW);
222  wc.hbrBackground = GetStockBrush(WHITE_BRUSH);
223  wc.lpszMenuName = textClassName;
224  wc.lpszClassName = textClassName;
225  ::RegisterClass (&wc);
226  Done = TRUE;
227  }
228 
229  menuBar = CreateMenu();
230  defaultMenu = CreatePopupMenu();
231  AppendMenu(menuBar,MF_POPUP,(UINT)defaultMenu,"Geant4");
232 
233  textBuffer = new TextBuffer();
234 
235  tmpSession = this;
236  mainWindow = ::CreateWindow(mainClassName,mainClassName,
237  WS_OVERLAPPEDWINDOW,
238  CW_USEDEFAULT,CW_USEDEFAULT,
239  0,0,
240  NULL,menuBar,
241  ::GetModuleHandle(NULL),
242  NULL);
243  tmpSession = NULL;
244  ::SetWindowLongPtr(mainWindow,GWLP_USERDATA,LONG(this));
245 
246  ::SetForegroundWindow(mainWindow);
247  ::ShowWindow(mainWindow,SW_SHOWDEFAULT);
248  ::UpdateWindow(mainWindow);
249 
250  if(UI!=NULL) UI->SetCoutDestination(this);
251 }
252 /***************************************************************************/
253 G4UIWin32::~G4UIWin32 (
254 )
255 /***************************************************************************/
256 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
257 {
259  if(UI!=NULL) {
260  UI->SetSession(NULL);
261  UI->SetCoutDestination(NULL);
262  }
263  delete textBuffer;
264  if(textWindow!=NULL) ::SetWindowLongPtr(textWindow,GWLP_USERDATA,LONG(NULL));
265  if(mainWindow!=NULL) {
266  ::SetWindowLongPtr(mainWindow,GWLP_USERDATA,LONG(NULL));
267  ::DestroyWindow(mainWindow);
268  }
269 }
270 /***************************************************************************/
271 G4UIsession* G4UIWin32::SessionStart (
272 )
273 /***************************************************************************/
274 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
275 {
276  if(interactorManager==NULL) return this;
277  Prompt ("session");
278  exitSession = false;
279  interactorManager->DisableSecondaryLoop ();
280  void* event;
281  while((event = interactorManager->GetEvent())!=NULL) {
282  interactorManager->DispatchEvent(event);
283  if(exitSession==true) break;
284  }
285  interactorManager->EnableSecondaryLoop ();
286  return this;
287 }
288 /***************************************************************************/
289 void G4UIWin32::Prompt (
290  const G4String& a_prompt
291 )
292 /***************************************************************************/
293 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
294 {
295 }
296 /***************************************************************************/
297 void G4UIWin32::SessionTerminate (
298 )
299 /***************************************************************************/
300 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
301 {
302 }
303 /***************************************************************************/
304 void G4UIWin32::PauseSessionStart (
305  const G4String& a_state
306 )
307 /***************************************************************************/
308 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
309 {
310  if(a_state=="G4_pause> ") {
311  SecondaryLoop ("Pause, type continue to exit this state");
312  }
313 
314  if(a_state=="EndOfEvent") {
315  // Picking with feed back in event data Done here !!!
316  SecondaryLoop ("End of event, type continue to exit this state");
317  }
318 }
319 /***************************************************************************/
320 void G4UIWin32::SecondaryLoop (
321  const G4String& a_prompt
322 )
323 /***************************************************************************/
324 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
325 {
326  if(interactorManager==NULL) return;
327  Prompt(a_prompt);
328  exitPause = false;
329  void* event;
330  while((event = interactorManager->GetEvent())!=NULL) {
331  interactorManager->DispatchEvent(event);
332  if(exitPause==true) break;
333  }
334  Prompt("session");
335 }
336 /***************************************************************************/
337 G4int G4UIWin32::ReceiveG4cout (
338  const G4String& a_string
339 )
340 /***************************************************************************/
341 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
342 {
343  TextAppendString((char*)a_string.data());
344  return 0;
345 }
346 /***************************************************************************/
347 G4int G4UIWin32::ReceiveG4cerr (
348  const G4String& a_string
349 )
350 /***************************************************************************/
351 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
352 {
353  TextAppendString((char*)a_string.data());
354  return 0;
355 }
356 /***************************************************************************/
357 G4bool G4UIWin32::GetHelpChoice(
358  G4int& aInt
359 )
360 /***************************************************************************/
361 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
362 {
363  fHelp = true;
364  //
365  if(interactorManager==NULL) return false;
366  Prompt("Help");
367  exitHelp = false;
368  void* event;
369  while((event = interactorManager->GetEvent())!=NULL) {
370  interactorManager->DispatchEvent(event);
371  if(exitHelp==true) break;
372  }
373  Prompt("session");
374  //
375  if(fHelp==false) return false;
376  aInt = fHelpChoice;
377  fHelp = false;
378  return true;
379 }
380 /***************************************************************************/
381 void G4UIWin32::ExitHelp(
382 ) const
383 /***************************************************************************/
384 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
385 {
386 }
387 /***************************************************************************/
388 void G4UIWin32::AddMenu (
389  const char* a_name
390 ,const char* a_label
391 )
392 /***************************************************************************/
393 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
394 {
395  if(a_name==NULL) return;
396  if(defaultMenu!=NULL) {
397  DeleteMenu (menuBar,0,MF_BYPOSITION);
398  defaultMenu = NULL;
399  }
400  HMENU hMenu = CreatePopupMenu();
401  AppendMenu(menuBar,MF_POPUP,(UINT)hMenu,a_label);
402  AddInteractor(a_name,(G4Interactor)hMenu);
403  DrawMenuBar(mainWindow);
404 }
405 /***************************************************************************/
406 void G4UIWin32::AddButton (
407  const char* a_menu
408 ,const char* a_label
409 ,const char* a_command
410 )
411 /***************************************************************************/
412 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
413 {
414  if(a_menu==NULL) return;
415  if(a_label==NULL) return;
416  if(a_command==NULL) return;
417  HMENU hMenu = (HMENU)GetInteractor(a_menu);
418  actionIdentifier++;
419  commands[actionIdentifier] = a_command;
420  AppendMenu (hMenu,MF_STRING,actionIdentifier,a_label);
421 }
422 /***************************************************************************/
423 G4String G4UIWin32::GetCommand (
424  int a_id
425 )
426 /***************************************************************************/
427 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
428 {
429  return commands[a_id];
430 }
431 /***************************************************************************/
432 /***************************************************************************/
433 /***************************************************************************/
434 LRESULT CALLBACK G4UIWin32::MainWindowProc (
435  HWND a_window
436 ,UINT a_message
437 ,WPARAM a_wParam
438 ,LPARAM a_lParam
439 )
440 /***************************************************************************/
441 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
442 {
443  static short charWidth,charHeight;
444 
445  switch (a_message) {
446  case WM_CREATE:{
447  HDC hdc;
448  TEXTMETRIC tm;
449  RECT rect;
450  GetWindowRect (a_window,&rect);
451 
452  hdc = GetDC (a_window);
453  GetTextMetrics (hdc,&tm);
454  charWidth = (short)tm.tmAveCharWidth;
455  charHeight = (short)(tm.tmHeight + tm.tmExternalLeading);
456  ReleaseDC (a_window,hdc);
457 
458  G4UIWin32* This = (G4UIWin32*)tmpSession;
459  if(This!=NULL) {
460  This->textWindow = CreateWindow (textClassName,NULL,
461  WS_CHILD | WS_VISIBLE | WS_VSCROLL,
462  0,0,
463  This->textCols * charWidth,
464  This->textRows * charHeight,
465  a_window,NULL,
466  GetWindowInstance(a_window),
467  NULL);
468  ::SetWindowLongPtr (This->textWindow,GWLP_USERDATA,LONG(This));
469 
470  This->editWindow = CreateWindow ("edit",NULL,
471  WS_CHILD | WS_VISIBLE | WS_BORDER,
472  0,This->textRows * charHeight,
473  This->textCols * charWidth,charHeight,
474  a_window,(HMENU)1,
475  GetWindowInstance(a_window),
476  NULL);
477  oldEditWindowProc = (WNDPROC)GetWindowLongPtr(This->editWindow,GWLP_WNDPROC);
478  SetWindowLongPtr (This->editWindow,GWLP_WNDPROC,(LONG)EditWindowProc);
479 
480  MoveWindow (a_window,
481  rect.left,rect.top,
482  2 * GetSystemMetrics(SM_CXFRAME) +
483  This->textCols * charWidth,
484  GetSystemMetrics(SM_CYCAPTION) +
485  2 * GetSystemMetrics(SM_CYFRAME) +
486  This->textRows * charHeight + charHeight,
487  TRUE);
488  }
489  }return 0;
490  case WM_SIZE:{
491  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
492  if(This!=NULL) {
493  // Client size :
494  int width = LOWORD(a_lParam);
495  int height = HIWORD(a_lParam);
496  int editHeight = /*2 * GetSystemMetrics(SM_CYBORDER) + */ charHeight;
497  MoveWindow (This->textWindow,
498  0,0,
499  width,height - editHeight,
500  FALSE);
501  MoveWindow (This->editWindow,
502  0,height - editHeight,
503  width,charHeight,
504  FALSE);
505  ((TextBuffer*)This->textBuffer)->SetHeightOfPage(height/charHeight);
506  }
507  }return 0;
508  case WM_SETFOCUS:{
509  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
510  if(This!=NULL) SetFocus (This->editWindow);
511  }return 0;
512  case WM_COMMAND:{
513  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
514  if(This!=NULL) {
515  if(This->fHelp==false) {
516  G4String command = This->GetCommand(a_wParam);
517  This->ApplyShellCommand (command,exitSession,exitPause);
518  }
519  }
520  }return 0;
521  case WM_DESTROY:
522  PostQuitMessage(0);
523  return 0;
524  }
525  return (DefWindowProc(a_window,a_message,a_wParam,a_lParam));
526 }
527 /***************************************************************************/
528 LRESULT CALLBACK G4UIWin32::TextWindowProc (
529  HWND a_window
530 ,UINT a_message
531 ,WPARAM a_wParam
532 ,LPARAM a_lParam
533 )
534 /***************************************************************************/
535 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
536 {
537  switch (a_message) {
538  case WM_PAINT:{
539  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
540  if(This!=NULL) {
541  TextBuffer* textBuffer = (TextBuffer*)This->textBuffer;
542  RECT rect;
543  GetClientRect (a_window,&rect);
544  PAINTSTRUCT ps;
545  HDC hdc = BeginPaint(a_window,&ps);
546  textBuffer->Draw(hdc,&rect);
547  EndPaint(a_window,&ps);
548  }
549  }return 0;
550  case WM_VSCROLL:{
551  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
552  if(This!=NULL) {
553  TextBuffer* textBuffer = (TextBuffer*)This->textBuffer;
554  int what = LOWORD(a_wParam);
555  switch(what) {
556  case SB_LINEUP:
557  textBuffer->DecrementEndOfPage();
558  break;
559  case SB_LINEDOWN:
560  textBuffer->IncrementEndOfPage();
561  break;
562  case SB_PAGEUP:
563  textBuffer->JumpUpEndOfPage();
564  break;
565  case SB_PAGEDOWN:
566  textBuffer->JumpDownEndOfPage();
567  break;
568  case SB_THUMBPOSITION:
569  case SB_THUMBTRACK:
570  textBuffer->SetEndOfPage(HIWORD(a_wParam));
571  break;
572  default:
573  return 0;
574  }
575  int eop = textBuffer->GetEndOfPage();
576  SetScrollPos(a_window,SB_VERT,eop,TRUE);
577  InvalidateRect(a_window,NULL,TRUE);
578  }}return 0;
579  case WM_DESTROY:
580  PostQuitMessage(0);
581  return 0;
582  }
583  return (DefWindowProc(a_window,a_message,a_wParam,a_lParam));
584 }
585 /***************************************************************************/
586 LRESULT CALLBACK G4UIWin32::EditWindowProc (
587  HWND a_window
588 ,UINT a_message
589 ,WPARAM a_wParam
590 ,LPARAM a_lParam
591 )
592 /***************************************************************************/
593 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
594 {
595  switch (a_message) {
596  case WM_KEYDOWN:
597  switch(a_wParam){
598  case VK_RETURN:{
599  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(
600  GetParent(a_window),GWLP_USERDATA);
601  char buffer[128];
602  GetWindowText (a_window,buffer,128);
603  G4String command (buffer);
604  //SetWindowText (a_window,"");
605  Edit_SetText(a_window,"");
606  Edit_SetSel(a_window,0,0);
607 
608  if(This!=NULL) {
609  if(This->fHelp==true) {
610  exitHelp = true;
611  This->fHelp = ConvertStringToInt(command.data(),This->fHelpChoice);
612  } else {
613  This->fHistory.push_back(command);
614  This->fHistoryPos = -1;
615  This->ApplyShellCommand (command,exitSession,exitPause);
616  }
617  }
618 
619  }break;
620  case VK_TAB:{
621  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(
622  GetParent(a_window),GWLP_USERDATA);
623  if( (This!=NULL) && (This->fHelp==true) ) break;
624  char buffer[128];
625  Edit_GetText(a_window,buffer,128);
626 
627  G4String command(buffer);
628 
629  if(This!=NULL) {
630  G4String cmd = This->Complete(command);
631  const char* d = cmd.data();
632  int l = strlen(d);
633  Edit_SetText(a_window,d);
634  Edit_SetSel(a_window,l,l);
635  }
636 
637  }break;
638  case VK_UP:{
639  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(
640  GetParent(a_window),GWLP_USERDATA);
641  if(This!=NULL) {
642  int pos = This->fHistoryPos== -1 ?
643  This->fHistory.size()-1 : This->fHistoryPos-1;
644  if((pos>=0)&&(pos<(int)This->fHistory.size())) {
645  G4String command = This->fHistory[pos];
646  const char* d = command.data();
647  int l = strlen(d);
648  Edit_SetText(a_window,d);
649  Edit_SetSel(a_window,l,l);
650  //
651  This->fHistoryPos = pos;
652  }
653  }
654  }return 0; //Do not jump into oldEditProc.
655  case VK_DOWN:{
656  G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(
657  GetParent(a_window),GWLP_USERDATA);
658  if(This!=NULL) {
659  int pos = This->fHistoryPos + 1;
660  if((pos>=0)&&(pos<(int)This->fHistory.size())) {
661  G4String command = This->fHistory[pos];
662  const char* d = command.data();
663  int l = strlen(d);
664  Edit_SetText(a_window,d);
665  Edit_SetSel(a_window,l,l);
666  //
667  This->fHistoryPos = pos;
668  } else if(pos>=(int)This->fHistory.size()) {
669  Edit_SetText(a_window,"");
670  Edit_SetSel(a_window,0,0);
671  //
672  This->fHistoryPos = -1;
673  }
674  }
675  }return 0; //Do not jump into oldEditProc.
676  }
677  }
678  return CallWindowProc(oldEditWindowProc,
679  a_window,a_message,
680  a_wParam,a_lParam);
681 }
682 /***************************************************************************/
683 void G4UIWin32::TextAppendString (
684  char* a_string
685 )
686 /***************************************************************************/
687 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
688 {
689  if( (a_string==NULL) || (a_string[0]=='\0') ) return;
690  if(textWindow==NULL) return;
691  if(((TextBuffer*)textBuffer)->AppendString(a_string)==true) {
692  // The appending triggers and end of line, and then updates window :
693  RECT rect;
694  GetClientRect(textWindow,&rect);
695  InvalidateRect(textWindow,NULL,TRUE); //To erase background.
696  HDC hdc = GetDC(textWindow);
697  ((TextBuffer*)textBuffer)->Draw(hdc,&rect);
698  ReleaseDC (textWindow,hdc);
699  int linen = ((TextBuffer*)textBuffer)->GetNumberOfLines();
700  SetScrollRange(textWindow,SB_VERT,0,linen-1,TRUE);
701  SetScrollPos(textWindow,SB_VERT,linen-1,TRUE);
702  }
703 }
704 //////////////////////////////////////////////////////////////////////////////
705 G4bool ConvertStringToInt(
706  const char* aString
707 ,int& aInt
708 )
709 //////////////////////////////////////////////////////////////////////////////
710 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
711 {
712  aInt = 0;
713  if(aString==NULL) return false;
714  char* s;
715  long value = strtol(aString,&s,10);
716  if(s==aString) return false;
717  aInt = value;
718  return true;
719 }
720 
721 
722 #endif
char cmd[1024]
Definition: tracer.cxx:25
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
const XML_Char * s
#define width
#define buffer
Definition: xmlparse.cc:611
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:213
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
void * G4Interactor
bool G4bool
Definition: G4Types.hh:79
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
const char * data() const
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:591
const XML_Char int const XML_Char * value