foobar2000 SDK  2015-08-03
Public Member Functions | Private Attributes
cfg_window_placement

#include <window_placement_helper.h>

+ Inheritance diagram for cfg_window_placement:

Public Member Functions

 cfg_window_placement (const GUID &p_guid)
 
void get_data_raw (stream_writer *p_stream, abort_callback &p_abort)
 
bool on_window_creation (HWND window)
 
void on_window_creation_silent (HWND window)
 
void on_window_destruction (HWND window)
 
bool read_from_window (HWND window)
 
void set_data_raw (stream_reader *p_stream, t_size p_sizehint, abort_callback &p_abort)
 
- Public Member Functions inherited from cfg_var
GUID get_guid () const
 
- Public Member Functions inherited from cfg_var_reader
 cfg_var_reader (const GUID &guid)
 
 ~cfg_var_reader ()
 
- Public Member Functions inherited from cfg_var_writer
 cfg_var_writer (const GUID &guid)
 
 ~cfg_var_writer ()
 

Private Attributes

WINDOWPLACEMENT m_data
 
pfc::list_hybrid_t< HWND, 2 > m_windows
 

Additional Inherited Members

- Static Public Member Functions inherited from cfg_var_reader
static void config_read_file (stream_reader *p_stream, abort_callback &p_abort)
 
- Static Public Member Functions inherited from cfg_var_writer
static void config_write_file (stream_writer *p_stream, abort_callback &p_abort)
 
- Data Fields inherited from cfg_var_reader
const GUID m_guid
 
- Data Fields inherited from cfg_var_writer
const GUID m_guid
 
- Protected Member Functions inherited from cfg_var
 cfg_var (const GUID &p_guid)
 

Detailed Description

Definition at line 6 of file window_placement_helper.h.

Constructor & Destructor Documentation

cfg_window_placement::cfg_window_placement ( const GUID p_guid)

Definition at line 125 of file window_placement_helper.cpp.

125  : cfg_var(p_guid)
126 {
127  memset(&m_data,0,sizeof(m_data));
128 }
cfg_var(const GUID &p_guid)
Definition: cfg_var.h:57

Member Function Documentation

void cfg_window_placement::get_data_raw ( stream_writer p_stream,
abort_callback p_abort 
)
virtual

Retrieves state of the variable. Called only from main thread, when writing configuration file.

Parameters
p_streamStream receiving state of the variable.

Implements cfg_var_writer.

Definition at line 98 of file window_placement_helper.cpp.

98  {
99  if (g_is_enabled()) {
100  {
101  t_size n, m = m_windows.get_count();
102  for(n=0;n<m;n++) {
103  HWND window = m_windows[n];
104  PFC_ASSERT(IsWindow(window));
105  if (IsWindow(window) && read_from_window(window)) break;
106  }
107  }
108 
109  if (m_data.length == sizeof(m_data)) {
110  p_stream->write_object(&m_data,sizeof(m_data),p_abort);
111  }
112  }
113 }
t_size get_count() const
Definition: list.h:365
bool read_from_window(HWND window)
size_t t_size
Definition: int_types.h:48
static bool g_is_enabled()
pfc::list_hybrid_t< HWND, 2 > m_windows
bool cfg_window_placement::on_window_creation ( HWND  window)

Definition at line 68 of file window_placement_helper.cpp.

69 {
70  bool ret = false;
71  PFC_ASSERT(!m_windows.have_item(window));
72  m_windows.add_item(window);
73 
74  if (g_is_enabled())
75  {
76  if (m_data.length==sizeof(m_data) && test_rect(&m_data.rcNormalPosition))
77  {
78  if (SetWindowPlacement(window,&m_data))
79  {
80  ret = true;
81  }
82  }
83  }
84 
85  return ret;
86 }
static bool test_rect(const RECT *rc)
t_size add_item(const T &item)
Definition: list.h:522
static bool g_is_enabled()
pfc::list_hybrid_t< HWND, 2 > m_windows
bool have_item(const t_search &p_item) const
Definition: list.h:569
void cfg_window_placement::on_window_creation_silent ( HWND  window)

Definition at line 64 of file window_placement_helper.cpp.

64  {
65  PFC_ASSERT(!m_windows.have_item(window));
66  m_windows.add_item(window);
67 }
t_size add_item(const T &item)
Definition: list.h:522
pfc::list_hybrid_t< HWND, 2 > m_windows
bool have_item(const t_search &p_item) const
Definition: list.h:569
void cfg_window_placement::on_window_destruction ( HWND  window)

Definition at line 89 of file window_placement_helper.cpp.

90 {
91  if (m_windows.have_item(window))
92  {
93  read_from_window(window);
94  m_windows.remove_item(window);
95  }
96 }
bool read_from_window(HWND window)
pfc::list_hybrid_t< HWND, 2 > m_windows
void remove_item(const T &item)
Definition: list.h:532
bool have_item(const t_search &p_item) const
Definition: list.h:569
bool cfg_window_placement::read_from_window ( HWND  window)

Definition at line 41 of file window_placement_helper.cpp.

42 {
43  WINDOWPLACEMENT wp = {};
44  if (g_is_enabled()) {
45  wp.length = sizeof(wp);
46  if (!GetWindowPlacement(window,&wp)) {
47  PFC_ASSERT(!"GetWindowPlacement fail!");
48  memset(&wp,0,sizeof(wp));
49  } else {
50  // bad, breaks with taskbar on top
51  /*if (wp.showCmd == SW_SHOWNORMAL) {
52  GetWindowRect(window, &wp.rcNormalPosition);
53  }*/
54  }
55  /*else
56  {
57  if (!IsWindowVisible(window)) wp.showCmd = SW_HIDE;
58  }*/
59  }
60  m_data = wp;
61  return m_data.length == sizeof(m_data);
62 }
static bool g_is_enabled()
void cfg_window_placement::set_data_raw ( stream_reader p_stream,
t_size  p_sizehint,
abort_callback p_abort 
)
virtual

Sets state of the variable. Called only from main thread, when reading configuration file.

Parameters
p_streamStream containing new state of the variable.
p_sizehintNumber of bytes contained in the stream; reading past p_sizehint bytes will fail (EOF).

Implements cfg_var_reader.

Definition at line 115 of file window_placement_helper.cpp.

115  {
116  if (p_sizehint == 0) return;
117  WINDOWPLACEMENT temp;
118  try {
119  p_stream->read_object(&temp,sizeof(temp),p_abort);
120  } catch(exception_io_data) {return;}
121  if (temp.length == sizeof(temp)) m_data = temp;
122 }

Field Documentation

WINDOWPLACEMENT cfg_window_placement::m_data
private

Definition at line 18 of file window_placement_helper.h.

pfc::list_hybrid_t<HWND,2> cfg_window_placement::m_windows
private

Definition at line 17 of file window_placement_helper.h.


The documentation for this class was generated from the following files: