g4tools  5.4.0
Public Member Functions | Protected Member Functions | List of all members
tools::WinTk::Shell Class Reference
Inheritance diagram for tools::WinTk::Shell:
Inheritance graph
[legend]
Collaboration diagram for tools::WinTk::Shell:
Collaboration graph
[legend]

Public Member Functions

 Shell (unsigned int aMask)
 
virtual ~Shell ()
 
virtual void show ()
 
void setTitle (const std::string &aString)
 
void setGeometry (int aX, int aY, unsigned int aWidth, unsigned int aHeight)
 
void setSize (unsigned int aWidth, unsigned int aHeight)
 
void setFocusWindow (HWND aWindow)
 
HWND focusWindow ()
 
void setSetFocusCallback (SetFocusCallback aCallback, void *aTag)
 
void callSetFocusCallback ()
 
HACCEL nativeAcceleratorTable ()
 
bool addAccelerator (const std::string &aString, int aID)
 
- Public Member Functions inherited from tools::WinTk::Component
 Component (const std::string &aType)
 
 Component (const std::string &aType, Component &aParent)
 
virtual ~Component ()
 
std::string name () const
 
void setName (const std::string &aName)
 
const std::string & type () const
 
HWND nativeWindow ()
 
Componentparent () const
 
void hide ()
 
virtual bool size (unsigned int &aWidth, unsigned int &aHeight)
 
virtual bool position (int &aX, int &aY)
 
ComponentfindFather (const std::string &aType)
 
bool setBackground (double aR, double aG, double aB)
 
void addCallback (const std::string &aName, Callback aFunction, void *aTag)
 
void removeCallback (const std::string &aName, Callback aFunction, void *aTag)
 
bool executeCallbacks (const std::string &aName, CallbackData &aData)
 
bool hasCallbacks (const std::string &aName) const
 

Protected Member Functions

 Shell (Shell &a_from)
 
Shelloperator= (Shell &)
 
- Protected Member Functions inherited from tools::WinTk::Component
 Component (Component &)
 
Componentoperator= (Component &)
 
void destroy ()
 
void rubberDrawLine (POINT &aBegin, POINT &aEnd)
 
void rubberDrawRect (POINT &aBegin, POINT &aEnd)
 

Additional Inherited Members

- Static Protected Member Functions inherited from tools::WinTk::Component
static void wm__destroy (HWND aWindow)
 
static LRESULT CALLBACK containerProc (HWND aWindow, UINT aMessage, WPARAM aWParam, LPARAM aLParam)
 
- Protected Attributes inherited from tools::WinTk::Component
HWND fWindow
 
ComponentfParent
 
std::vector< NamedCallbacks > fCallbacks
 
std::string fName
 

Detailed Description

Definition at line 351 of file WinTk.

Constructor & Destructor Documentation

◆ Shell() [1/2]

tools::WinTk::Shell::Shell ( unsigned int  aMask)
inline

Definition at line 353 of file WinTk.

354  :Component("Shell")
355  ,fFocusWindow(0)
356  ,fSetFocusCallback(0)
357  ,fSetFocusTag(0)
358  ,fAcceleratorTable(0)
359  {
360  static char sWindowClassName[] = "WinTk::Shell";
361  static bool done = false;
362  if(!done) {
363  WNDCLASS wc;
364  wc.style = CS_HREDRAW | CS_VREDRAW;
365  wc.lpfnWndProc = (WNDPROC)Shell::proc;
366  wc.cbClsExtra = 0;
367  wc.cbWndExtra = 0;
368  wc.hInstance = ::GetModuleHandle(NULL);
369  wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
370  wc.hCursor = LoadCursor(NULL,IDC_ARROW);
371  wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
372  wc.lpszMenuName = sWindowClassName;
373  wc.lpszClassName = sWindowClassName;
374  ::RegisterClass(&wc);
375  done = true;
376  }
377 
378  fWindow = ::CreateWindow(sWindowClassName,
379  NULL,
380  aMask, //WS_OVERLAPPEDWINDOW,
381  CW_USEDEFAULT,CW_USEDEFAULT,
382  400,400,
383  NULL,NULL,
384  ::GetModuleHandle(NULL),
385  NULL);
386  if(!fWindow) return;
387  ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG_PTR(this));
388  }

◆ ~Shell()

virtual tools::WinTk::Shell::~Shell ( )
inlinevirtual

Definition at line 389 of file WinTk.

389  {
390  if(fAcceleratorTable) {
391  ::DestroyAcceleratorTable(fAcceleratorTable);
392  fAcceleratorTable = 0;
393  }
394  destroy();
395  }

◆ Shell() [2/2]

tools::WinTk::Shell::Shell ( Shell a_from)
inlineprotected

Definition at line 397 of file WinTk.

397 :Component(a_from) {}

Member Function Documentation

◆ addAccelerator()

bool tools::WinTk::Shell::addAccelerator ( const std::string &  aString,
int  aID 
)
inline

Definition at line 444 of file WinTk.

444  {
445  //printf("debug : accel : %s %d\n",aString.c_str(),aID);
446  // aString should be of the form : "a" or "Ctrl+a".
447  ACCEL acc;
448  //acc.fVirt : FALT, FCONTROL, FNOINVERT, FSHIFT, FVIRTKEY
449  {acc.cmd = aID;
450  std::vector<std::string> words;
451  std::string s(aString);
453  tools::words(s,"+",false,words);
454  if(words.size()==1) {
455  acc.fVirt = FVIRTKEY;
456  if(!string_to_VK(words[0],acc.key)) return false;
457  } else if((words.size()==2)&&(words[1].size())) {
458  if(words[0]=="CTRL") {
459  acc.fVirt = FCONTROL;
460  } else if(words[0]=="ALT") {
461  acc.fVirt = FALT;
462  } else if(words[0]=="SHIFT") {
463  acc.fVirt = FSHIFT;
464  } else {
465  return false;
466  }
467  acc.fVirt |= FVIRTKEY;
468  if(!string_to_VK(words[1],acc.key)) return false;
469  } else {
470  return false;
471  }}
472 
473  if(!fAcceleratorTable) {
474  fAcceleratorTable = ::CreateAcceleratorTable(&acc,1);
475  } else {
476  int n = ::CopyAcceleratorTable(fAcceleratorTable,NULL,0);
477  ACCEL* tbl = new ACCEL[n+1];
478  ::CopyAcceleratorTable(fAcceleratorTable,tbl,n);
479  ACCEL& tacc = tbl[n];
480  tacc.fVirt = acc.fVirt;
481  tacc.key = acc.key;
482  tacc.cmd = acc.cmd;
483  ::DestroyAcceleratorTable(fAcceleratorTable);
484  fAcceleratorTable = ::CreateAcceleratorTable(tbl,n+1);
485  delete [] tbl;
486  }
487 
488  return true;
489  }

◆ callSetFocusCallback()

void tools::WinTk::Shell::callSetFocusCallback ( )
inline

Definition at line 438 of file WinTk.

438  {
439  if(!fSetFocusCallback) return;
440  fSetFocusCallback(this,fSetFocusTag);
441  }

◆ focusWindow()

HWND tools::WinTk::Shell::focusWindow ( )
inline

Definition at line 432 of file WinTk.

432 {return fFocusWindow;}

◆ nativeAcceleratorTable()

HACCEL tools::WinTk::Shell::nativeAcceleratorTable ( )
inline

Definition at line 442 of file WinTk.

442 {return fAcceleratorTable;}

◆ operator=()

Shell& tools::WinTk::Shell::operator= ( Shell )
inlineprotected

Definition at line 398 of file WinTk.

398 {return *this;}

◆ setFocusWindow()

void tools::WinTk::Shell::setFocusWindow ( HWND  aWindow)
inline

Definition at line 431 of file WinTk.

431 {fFocusWindow = aWindow;}

◆ setGeometry()

void tools::WinTk::Shell::setGeometry ( int  aX,
int  aY,
unsigned int  aWidth,
unsigned int  aHeight 
)
inline

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 411 of file WinTk.

411  {
413  // Given width, height is the desired client area.
415  if(!fWindow) return;
416  int hborder = ::GetSystemMetrics(SM_CYCAPTION);
417  if(::GetWindowLongPtr(fWindow,GWLP_ID)) // Has a menubar.
418  hborder += ::GetSystemMetrics(SM_CYMENU);
419  ::MoveWindow(fWindow,aX,aY,aWidth,hborder + aHeight,TRUE);
420  }

◆ setSetFocusCallback()

void tools::WinTk::Shell::setSetFocusCallback ( SetFocusCallback  aCallback,
void *  aTag 
)
inline

Definition at line 434 of file WinTk.

434  {
435  fSetFocusCallback = aCallback;
436  fSetFocusTag = aTag;
437  }

◆ setSize()

void tools::WinTk::Shell::setSize ( unsigned int  aWidth,
unsigned int  aHeight 
)
inline

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

Definition at line 421 of file WinTk.

421  {
423  // Given width, height is the desired client area.
425  if(!fWindow) return;
426  int hborder = ::GetSystemMetrics(SM_CYCAPTION);
427  RECT rect;
428  ::GetWindowRect(fWindow,&rect);
429  ::MoveWindow(fWindow,rect.left,rect.top,aWidth,hborder + aHeight,TRUE);
430  }

◆ setTitle()

void tools::WinTk::Shell::setTitle ( const std::string &  aString)
inline

Definition at line 407 of file WinTk.

407  {
408  if(!fWindow) return;
409  ::SetWindowText(fWindow,aString.c_str());
410  }

◆ show()

virtual void tools::WinTk::Shell::show ( )
inlinevirtual

Reimplemented from tools::WinTk::Component.

Definition at line 400 of file WinTk.

400  {
401  if(!fWindow) return;
402  ::SetForegroundWindow(fWindow);
403  ::ShowWindow(fWindow,SW_SHOWDEFAULT);
404  ::UpdateWindow(fWindow);
405  ::DrawMenuBar(fWindow);
406  }

The documentation for this class was generated from the following file:
tools::touppercase
void touppercase(std::string &a_string)
Definition: touplow:18
tools::WinTk::Component::destroy
void destroy()
Definition: WinTk:297
tools::words
void words(const std::string &a_string, const std::string &a_sep, bool a_take_empty, std::vector< std::string > &a_words, bool a_clear=true)
Definition: words:12
tools::WinTk::Component::Component
Component(const std::string &aType)
Definition: WinTk:42
tools::WinTk::Component::fWindow
HWND fWindow
Definition: WinTk:342