Commit f34f65ea authored by Davis King's avatar Davis King

Changed the base_window so that it doesn't have any requirement that it not

be closed before calling its member functions.  Now doing so is just a no op.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402612
parent 80c95989
...@@ -1579,7 +1579,6 @@ namespace dlib ...@@ -1579,7 +1579,6 @@ namespace dlib
) )
{ {
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
shared_ptr_thread_safe<event_handler_thread> globals(global_data());
user_event_type e; user_event_type e;
e.w = hwnd; e.w = hwnd;
...@@ -1713,19 +1712,17 @@ namespace dlib ...@@ -1713,19 +1712,17 @@ namespace dlib
const std::wstring& title const std::wstring& title
) )
{ {
DLIB_ASSERT(is_closed() == false,
"\tvoid base_window::set_title"
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
);
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
auto_mutex M(wm);
if (has_been_destroyed == true)
return;
// call the SetWindowText function with our arguments but make sure it is from // call the SetWindowText function with our arguments but make sure it is from
// the event thread. We have to do this because the SetWindowText() apparently blocks // the event thread. We have to do this because the SetWindowText() apparently blocks
// until something happens in the event thread so we have to // until something happens in the event thread so we have to
// do this to avoid possible deadlocks. // do this to avoid possible deadlocks.
auto_mutex M(wm);
if (get_thread_id() == globals->event_thread_id) if (get_thread_id() == globals->event_thread_id)
{ {
SetWindowTextW(hwnd,title.c_str()); SetWindowTextW(hwnd,title.c_str());
...@@ -1752,12 +1749,11 @@ namespace dlib ...@@ -1752,12 +1749,11 @@ namespace dlib
show ( show (
) )
{ {
DLIB_ASSERT(is_closed() == false,
"\tvoid base_window::show"
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
);
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
auto_mutex M(wm);
if (has_been_destroyed == true)
return;
show_window(hwnd); show_window(hwnd);
if (style != WS_CHILD) if (style != WS_CHILD)
give_window_focus(hwnd); give_window_focus(hwnd);
...@@ -1769,12 +1765,11 @@ namespace dlib ...@@ -1769,12 +1765,11 @@ namespace dlib
hide( hide(
) )
{ {
DLIB_ASSERT(is_closed() == false,
"\tvoid base_window::hide"
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
);
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
auto_mutex M(wm);
if (has_been_destroyed == true)
return;
hide_window(hwnd); hide_window(hwnd);
} }
...@@ -1787,14 +1782,10 @@ namespace dlib ...@@ -1787,14 +1782,10 @@ namespace dlib
) )
{ {
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
DLIB_ASSERT(is_closed() == false,
"\tvoid base_window::set_size"
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
<< "\n\twidth: " << width_
<< "\n\theight: " << height_
);
auto_mutex M(wm); auto_mutex M(wm);
if (has_been_destroyed == true)
return;
if (get_thread_id() == globals->event_thread_id) if (get_thread_id() == globals->event_thread_id)
{ {
RECT info; RECT info;
...@@ -1875,14 +1866,10 @@ namespace dlib ...@@ -1875,14 +1866,10 @@ namespace dlib
) )
{ {
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
DLIB_ASSERT(is_closed() == false,
"\tvoid base_window::set_pos"
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
<< "\n\tx: " << x_
<< "\n\ty: " << y_
);
auto_mutex M(wm); auto_mutex M(wm);
if (has_been_destroyed == true)
return;
if (get_thread_id() == globals->event_thread_id) if (get_thread_id() == globals->event_thread_id)
{ {
RECT info; RECT info;
...@@ -1938,11 +1925,12 @@ namespace dlib ...@@ -1938,11 +1925,12 @@ namespace dlib
long& y_ long& y_
) )
{ {
DLIB_ASSERT(is_closed() == false, auto_mutex M(wm);
"\tvoid base_window::get_pos" x_ = 0;
<< "\n\tYou can't do this to a window that has been closed." y_ = 0;
<< "\n\tthis: " << this if (has_been_destroyed == true)
); return;
POINT p; POINT p;
p.x = 0; p.x = 0;
p.y = 0; p.y = 0;
...@@ -1960,11 +1948,12 @@ namespace dlib ...@@ -1960,11 +1948,12 @@ namespace dlib
unsigned long& height unsigned long& height
) const ) const
{ {
DLIB_ASSERT(is_closed() == false, auto_mutex M(wm);
"\tvoid base_window::get_display_size" width = 0;
<< "\n\tYou can't do this to a window that has been closed." height = 0;
<< "\n\tthis: " << this if (has_been_destroyed == true)
); return;
RECT rc; RECT rc;
GetWindowRect(hwnd, &rc); GetWindowRect(hwnd, &rc);
...@@ -1997,11 +1986,12 @@ namespace dlib ...@@ -1997,11 +1986,12 @@ namespace dlib
unsigned long& height unsigned long& height
) const ) const
{ {
DLIB_ASSERT(is_closed() == false, auto_mutex M(wm);
"\tvoid base_window::get_size" width = 0;
<< "\n\tYou can't do this to a window that has been closed." height = 0;
<< "\n\tthis: " << this if (has_been_destroyed == true)
); return;
RECT r; RECT r;
GetClientRect(hwnd,&r); GetClientRect(hwnd,&r);
...@@ -2017,6 +2007,7 @@ namespace dlib ...@@ -2017,6 +2007,7 @@ namespace dlib
const rectangle& rect const rectangle& rect
) )
{ {
auto_mutex M(wm);
if (rect.is_empty() == false && !has_been_destroyed) if (rect.is_empty() == false && !has_been_destroyed)
{ {
RECT info; RECT info;
...@@ -2037,6 +2028,10 @@ namespace dlib ...@@ -2037,6 +2028,10 @@ namespace dlib
long y long y
) )
{ {
auto_mutex M(wm);
if (has_been_destroyed == true)
return;
HIMC hImc = ImmGetContext(hwnd); HIMC hImc = ImmGetContext(hwnd);
COMPOSITIONFORM cf; COMPOSITIONFORM cf;
......
...@@ -1739,11 +1739,9 @@ namespace dlib ...@@ -1739,11 +1739,9 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
auto_mutex M(wm); auto_mutex M(wm);
DLIB_ASSERT(is_closed() == false, if (has_been_destroyed == true)
"\tvoid base_window::set_title" return;
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
);
// I'm pretty sure the pointer won't be modified even though // I'm pretty sure the pointer won't be modified even though
// it isn't const anymore. // it isn't const anymore.
wchar_t *title = const_cast<wchar_t *>(title_.c_str()); wchar_t *title = const_cast<wchar_t *>(title_.c_str());
...@@ -1762,11 +1760,9 @@ namespace dlib ...@@ -1762,11 +1760,9 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
auto_mutex M(wm); auto_mutex M(wm);
DLIB_ASSERT(is_closed() == false, if (has_been_destroyed == true)
"\tvoid base_window::show" return;
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
);
XMapRaised(x11_stuff.globals->disp,x11_stuff.hwnd); XMapRaised(x11_stuff.globals->disp,x11_stuff.hwnd);
XFlush(x11_stuff.globals->disp); XFlush(x11_stuff.globals->disp);
} }
...@@ -1791,11 +1787,9 @@ namespace dlib ...@@ -1791,11 +1787,9 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
auto_mutex M(wm); auto_mutex M(wm);
DLIB_ASSERT(is_closed() == false, if (has_been_destroyed == true)
"\tvoid base_window::hide" return;
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
);
XUnmapWindow(x11_stuff.globals->disp,x11_stuff.hwnd); XUnmapWindow(x11_stuff.globals->disp,x11_stuff.hwnd);
XFlush(x11_stuff.globals->disp); XFlush(x11_stuff.globals->disp);
} }
...@@ -1810,13 +1804,9 @@ namespace dlib ...@@ -1810,13 +1804,9 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
auto_mutex a(wm); auto_mutex a(wm);
DLIB_ASSERT(is_closed() == false, if (has_been_destroyed == true)
"\tvoid base_window::set_size" return;
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
<< "\n\twidth: " << width_
<< "\n\theight: " << height_
);
// do some sanity checking on these values // do some sanity checking on these values
if (width_ < 1) if (width_ < 1)
...@@ -1855,13 +1845,9 @@ namespace dlib ...@@ -1855,13 +1845,9 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
auto_mutex a(wm); auto_mutex a(wm);
DLIB_ASSERT(is_closed() == false, if (has_been_destroyed == true)
"\tvoid base_window::set_pos" return;
<< "\n\tYou can't do this to a window that has been closed."
<< "\n\tthis: " << this
<< "\n\tx: " << x_
<< "\n\ty: " << y_
);
x = x_; x = x_;
y = y_; y = y_;
...@@ -1882,11 +1868,10 @@ namespace dlib ...@@ -1882,11 +1868,10 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
auto_mutex a(wm); auto_mutex a(wm);
DLIB_ASSERT(is_closed() == false, x_ = 0;
"\tvoid base_window::get_pos" y_ = 0;
<< "\n\tYou can't do this to a window that has been closed." if (has_been_destroyed == true)
<< "\n\tthis: " << this return;
);
// we can't really trust the values we have for x and y because some window managers // we can't really trust the values we have for x and y because some window managers
// will have reported bogus values back in the ConfigureNotify event. So just to be // will have reported bogus values back in the ConfigureNotify event. So just to be
...@@ -1910,11 +1895,11 @@ namespace dlib ...@@ -1910,11 +1895,11 @@ namespace dlib
) const ) const
{ {
auto_mutex M(wm); auto_mutex M(wm);
DLIB_ASSERT(is_closed() == false, width_ = 0;
"\tvoid base_window::get_size" height_ = 0;
<< "\n\tYou can't do this to a window that has been closed." if (has_been_destroyed == true)
<< "\n\tthis: " << this return;
);
width_ = width; width_ = width;
height_ = height; height_ = height;
...@@ -1930,11 +1915,10 @@ namespace dlib ...@@ -1930,11 +1915,10 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
auto_mutex M(wm); auto_mutex M(wm);
DLIB_ASSERT(is_closed() == false, width_ = 0;
"\tvoid base_window::get_display_size" height_ = 0;
<< "\n\tYou can't do this to a window that has been closed." if (has_been_destroyed == true)
<< "\n\tthis: " << this return;
);
int screen_number = XScreenNumberOfScreen(x11_stuff.globals->screen); int screen_number = XScreenNumberOfScreen(x11_stuff.globals->screen);
width_ = DisplayWidth(x11_stuff.globals->disp, screen_number); width_ = DisplayWidth(x11_stuff.globals->disp, screen_number);
...@@ -1975,6 +1959,9 @@ namespace dlib ...@@ -1975,6 +1959,9 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
auto_mutex a(wm); auto_mutex a(wm);
if (has_been_destroyed == true)
return;
if (!x11_stuff.xic || !(x11_stuff.globals->xim_style & XIMPreeditPosition)) return; if (!x11_stuff.xic || !(x11_stuff.globals->xim_style & XIMPreeditPosition)) return;
XVaNestedList xva_nlist; XVaNestedList xva_nlist;
......
...@@ -354,48 +354,43 @@ namespace dlib ...@@ -354,48 +354,43 @@ namespace dlib
const std::string& title const std::string& title
); );
/*! /*!
requires
- is_closed() == false
ensures ensures
- sets the title of the window - if (is_closed() == false) then
- sets the title of the window
!*/ !*/
void set_title ( void set_title (
const std::wstring& title const std::wstring& title
); );
/*! /*!
requires
- is_closed() == false
ensures ensures
- sets the title of the window - if (is_closed() == false) then
- sets the title of the window
!*/ !*/
void set_title ( void set_title (
const dlib::ustring& title const dlib::ustring& title
); );
/*! /*!
requires
- is_closed() == false
ensures ensures
- sets the title of the window - if (is_closed() == false) then
- sets the title of the window
!*/ !*/
virtual void show ( virtual void show (
); );
/*! /*!
requires
- is_closed() == false
ensures ensures
- this window will appear on the screen - if (is_closed() == false) then
- this window will appear on the screen
!*/ !*/
virtual void hide( virtual void hide(
); );
/*! /*!
requires
- is_closed() == false
ensures ensures
- the window does not appear on the screen - if (is_closed() == false) then
- the window does not appear on the screen
!*/ !*/
void set_size ( void set_size (
...@@ -403,15 +398,14 @@ namespace dlib ...@@ -403,15 +398,14 @@ namespace dlib
int height int height
); );
/*! /*!
requires
- is_closed() == false
ensures ensures
- The width of the client area of this window is at least width - if (is_closed() == false) then
pixels. - The width of the client area of this window is at least width
- The height of the client area of this window is at least height pixels.
pixels. - The height of the client area of this window is at least height
- if (the window wasn't already this size) then pixels.
- triggers the on_window_resized() callback - if (the window wasn't already this size) then
- triggers the on_window_resized() callback
!*/ !*/
void set_pos ( void set_pos (
...@@ -419,12 +413,11 @@ namespace dlib ...@@ -419,12 +413,11 @@ namespace dlib
long y long y
); );
/*! /*!
requires
- is_closed() == false
ensures ensures
- sets the upper left corner of this window to the position (x,y) - if (is_closed() == false) then
on the desktop. Note that the origin (0,0) is at the upper left - sets the upper left corner of this window to the position (x,y)
corner of the desktop. on the desktop. Note that the origin (0,0) is at the upper left
corner of the desktop.
!*/ !*/
void get_pos ( void get_pos (
...@@ -432,15 +425,17 @@ namespace dlib ...@@ -432,15 +425,17 @@ namespace dlib
long& y long& y
) const; ) const;
/*! /*!
requires
- is_closed() == false
ensures ensures
- #x == the x coordinate of the upper left corner of the client area of - if (is_closed() == false) then
this window. - #x == the x coordinate of the upper left corner of the client area of
- #y == the y coordinate of the upper left corner of the client area of this window.
this window. - #y == the y coordinate of the upper left corner of the client area of
- i.e. the point (#x,#y) on the desktop is coincident with the point this window.
(0,0) in the client area of this window. - i.e. the point (#x,#y) on the desktop is coincident with the point
(0,0) in the client area of this window.
- else
- #x == 0
- #y == 0
!*/ !*/
void get_size ( void get_size (
...@@ -448,11 +443,13 @@ namespace dlib ...@@ -448,11 +443,13 @@ namespace dlib
unsigned long& height unsigned long& height
) const; ) const;
/*! /*!
requires
- is_closed() == false
ensures ensures
- #width == the width of the client area of this window in pixels - if (is_closed() == false) then
- #height == the height of the client area of this window in pixels - #width == the width of the client area of this window in pixels
- #height == the height of the client area of this window in pixels
- else
- #width == 0
- #height == 0
!*/ !*/
void get_display_size ( void get_display_size (
...@@ -460,11 +457,13 @@ namespace dlib ...@@ -460,11 +457,13 @@ namespace dlib
unsigned long& height unsigned long& height
) const; ) const;
/*! /*!
requires
- is_closed() == false
ensures ensures
- #width == the width in pixels of the display device that contains this window - if (is_closed() == false) then
- #height == the height in pixels of the display device that contains this window - #width == the width in pixels of the display device that contains this window
- #height == the height in pixels of the display device that contains this window
- else
- #width == 0
- #height == 0
!*/ !*/
void invalidate_rectangle ( void invalidate_rectangle (
...@@ -499,8 +498,9 @@ namespace dlib ...@@ -499,8 +498,9 @@ namespace dlib
); );
/*! /*!
ensures ensures
- sets the left-top position of input method rectangle used - if (is_closed() == false) then
for wide character input methods. - sets the left-top position of input method rectangle used
for wide character input methods.
!*/ !*/
protected: protected:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment