00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include <wx/util.h>
00013
00014 #if defined(__WXMSW__)
00015 #include <wx/msw/private.h>
00016 #endif
00017
00018 namespace wxUtil {
00019
00020 void WriteString( wxOutputStream& stream, const wxString& string ) {
00021
00022 wxCharBuffer buffer = string.mb_str(wxConvLibc);
00023 size_t size = string.Length();
00024 stream.Write(&size, sizeof(size));
00025 stream.Write(buffer, size);
00026 }
00027
00028 wxString ReadString( wxInputStream& stream ) {
00029
00030 size_t size = 0;
00031 stream.Read( &size, sizeof( size ) );
00032 char* data = new char[size+1];
00033 stream.Read(data, size);
00034 data[size] = 0;
00035 wxString string(data, wxConvLibc);
00036 delete data;
00037 return string;
00038 }
00039
00040 bool SaveCheckFilename( const wxString& file ) {
00041 if( wxFile::Exists( file ) && !wxFile::Access( file, wxFile::write ) ) {
00042 return false;
00043 }
00044 return true;
00045 }
00046
00047 bool LoadCheckFilename( const wxString& file ) {
00048 if( !wxFile::Exists( file ) ) {
00049 return false;
00050 }
00051 return true;
00052 }
00053
00054 void WriteWindowLayout( wxOutputStream& stream, wxWindow * pWindow ) {
00055 wxASSERT(pWindow);
00056
00057
00058 WriteString( stream, wxT("<window>") );
00059
00060 wxRect size = pWindow->GetRect();
00061 wxFrame * pFrame = wxDynamicCast( pWindow, wxFrame );
00062 if( pFrame ) {
00063
00064 bool isMaximized = pFrame->IsMaximized();
00065 stream.Write( &isMaximized, sizeof( isMaximized ) );
00066
00067 #if defined(__WXMSW__)
00068 if( isMaximized ) {
00069
00070 WINDOWPLACEMENT wndPl;
00071 ::GetWindowPlacement( (HWND)pFrame->GetHandle(), &wndPl );
00072 RECT r = wndPl.rcNormalPosition;
00073 size.SetPosition( wxPoint( r.left, r.top ) );
00074 size.SetSize( wxSize( r.right - r.left, r.bottom - r.top ) );
00075 }
00076 #endif
00077 }
00078 else {
00079
00080 bool isMaximized = false;
00081 stream.Write( &isMaximized, sizeof( isMaximized ) );
00082 }
00083
00084
00085 stream.Write( &size.x, sizeof( size.x ) );
00086 stream.Write( &size.y, sizeof( size.y ) );
00087 stream.Write( &size.width, sizeof( size.width ) );
00088 stream.Write( &size.height, sizeof( size.height ) );
00089 }
00090
00091 void ReadWindowLayout( wxInputStream& stream, wxWindow * pWindow ) {
00092 wxASSERT(pWindow);
00093
00094
00095 wxString windowTag = ReadString( stream );
00096 if( windowTag == wxT("<window>") ) {
00097
00098 bool maximized = false;
00099 stream.Read( &maximized, sizeof( maximized ) );
00100 wxRect size;
00101 stream.Read( &size.x, sizeof( size.x ) );
00102 stream.Read( &size.y, sizeof( size.y ) );
00103 stream.Read( &size.width, sizeof( size.width ) );
00104 stream.Read( &size.height, sizeof( size.height ) );
00105
00106 wxFrame * pFrame = wxDynamicCast( pWindow, wxFrame );
00107 if( pFrame ) {
00108 #if defined(__WXMSW__)
00109 if( maximized ) {
00110
00111 WINDOWPLACEMENT wndPl;
00112 ::GetWindowPlacement( (HWND)pFrame->GetHandle(), &wndPl );
00113 wndPl.showCmd = SW_MAXIMIZE;
00114 RECT r = { size.x, size.y, size.x + size.width, size.y + size.height };
00115 wndPl.rcNormalPosition = r;
00116 ::SetWindowPlacement( (HWND)pFrame->GetHandle(), &wndPl );
00117 return;
00118 }
00119 #endif
00120 }
00121 pWindow->SetSize( size );
00122 }
00123 }
00124
00125 }
00126