Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "vgui_mfc_window.h"
00018 #include "vgui_mfc_adaptor.h"
00019 #include "vgui_mfc_mainfrm.h"
00020 #include "vgui_mfc.h"
00021 #include "vgui_mfc_utils.h"
00022 #include "vgui_mfc_statusbar.h"
00023 #include <vgui/vgui.h>
00024 #include <vgui/vgui_gl.h>
00025
00026 static bool first_window = true;
00027
00028 void vgui_mfc_window::init_window(char const *title,
00029 vgui_menu const &menubar,
00030 bool has_menu,
00031 unsigned width, unsigned height,
00032 int posx,
00033 int posy)
00034 {
00035
00036 {
00037
00038 CWinApp *app = AfxGetApp();
00039 app->GetMainWnd()->SetWindowText(title);
00040 pos1 = app->GetFirstDocTemplatePosition();
00041 CDocTemplate *tmpl = app->GetNextDocTemplate(pos1);
00042 pos2 = tmpl->GetFirstDocPosition();
00043 CDocument *pdoc = tmpl->GetNextDoc(pos2);
00044 pos3 = pdoc->GetFirstViewPosition();
00045 mfcwin = (vgui_mfc_adaptor *)pdoc->GetNextView(pos3);
00046 mfcwin->set_window( this );
00047 if (has_menu)
00048 set_menubar(menubar);
00049 statusbar = new vgui_mfc_statusbar();
00050 CWnd *main_wnd = app->GetMainWnd();
00051 ((vgui_mfc_mainfrm *)main_wnd)->SetStatusBar(statusbar);
00052 vgui::out.rdbuf(statusbar->statusbuf);
00053
00054 WINDOWPLACEMENT w_placement;
00055
00056 main_wnd->GetWindowPlacement(&w_placement);
00057
00058 w_placement.rcNormalPosition.right = w_placement.rcNormalPosition.left+width;
00059 w_placement.rcNormalPosition.bottom = w_placement.rcNormalPosition.top+height;
00060
00061 main_wnd->SetWindowPlacement(&w_placement);
00062 first_window = false;
00063 }
00064 }
00065
00066
00067 vgui_mfc_window::vgui_mfc_window(char const *title,
00068 unsigned width, unsigned height,
00069 int posx,
00070 int posy)
00071 : vgui_window()
00072 , mfcwin(0)
00073 , statusbar(0)
00074 {
00075 init_window(title, vgui_menu(), false, width, height, posx, posy);
00076 }
00077
00078
00079 vgui_mfc_window::vgui_mfc_window(unsigned width, unsigned height,
00080 vgui_menu const &menubar,
00081 char const *title)
00082 : vgui_window()
00083 , mfcwin(0)
00084 , statusbar(0)
00085 {
00086 init_window(title, menubar, true, width, height, 0, 0);
00087 }
00088
00089
00090 vgui_mfc_window::~vgui_mfc_window()
00091 {
00092 glFlush();
00093
00094
00095
00096 delete statusbar;
00097 statusbar = 0;
00098 }
00099
00100
00101 void vgui_mfc_window::set_menubar(vgui_menu const &m)
00102 {
00103 menubar = m;
00104 vgui_mfc::instance()->utils->set_menu(menubar);
00105 }
00106
00107
00108 vgui_adaptor* vgui_mfc_window::get_adaptor()
00109 {
00110 return mfcwin;
00111 }
00112
00113
00114 vgui_statusbar* vgui_mfc_window::get_statusbar()
00115 {
00116 return statusbar;
00117 }
00118
00119 void vgui_mfc_window::show()
00120 {
00121 CWnd *wnd = AfxGetApp()->GetMainWnd();
00122 wnd->ShowWindow(SW_SHOWNORMAL);
00123 }
00124
00125 void vgui_mfc_window::hide()
00126 {
00127 CWnd *wnd = AfxGetApp()->GetMainWnd();
00128 wnd->ShowWindow(SW_HIDE);
00129 }
00130
00131 void vgui_mfc_window::enable_hscrollbar(bool show)
00132 {
00133 CWnd *wnd = AfxGetApp()->GetMainWnd();
00134 wnd->ShowScrollBar(SB_HORZ,show);
00135 }
00136
00137 void vgui_mfc_window::enable_vscrollbar(bool show)
00138 {
00139 CWnd *wnd = AfxGetApp()->GetMainWnd();
00140 wnd->ShowScrollBar(SB_VERT,show);
00141 }
00142
00143 void vgui_mfc_window::iconify()
00144 {
00145 CWnd *wnd = AfxGetApp()->GetMainWnd();
00146 wnd->ShowWindow(SW_MINIMIZE);
00147 }
00148
00149 void vgui_mfc_window::reshape(unsigned w, unsigned h)
00150 {
00151 CWnd *main_wnd = AfxGetApp()->GetMainWnd();
00152 WINDOWPLACEMENT w_placement;
00153
00154 main_wnd->GetWindowPlacement(&w_placement);
00155
00156
00157
00158
00159
00160
00161 int kludge_width_margin = 35, kludge_height_margin=100;
00162
00163 w_placement.rcNormalPosition.right = w_placement.rcNormalPosition.left+w+kludge_width_margin;
00164 w_placement.rcNormalPosition.bottom = w_placement.rcNormalPosition.top+h+kludge_height_margin;
00165
00166 main_wnd->SetWindowPlacement(&w_placement);
00167 }
00168
00169 void vgui_mfc_window::reposition(int x,int y)
00170 {
00171 CWnd *main_wnd = AfxGetApp()->GetMainWnd();
00172 WINDOWPLACEMENT w_placement;
00173
00174
00175 main_wnd->GetWindowPlacement(&w_placement);
00176 int width = w_placement.rcNormalPosition.right -
00177 w_placement.rcNormalPosition.left;
00178 int height = w_placement.rcNormalPosition.bottom -
00179 w_placement.rcNormalPosition.top;
00180
00181
00182 w_placement.rcNormalPosition.left=x;
00183 w_placement.rcNormalPosition.top=y;
00184
00185
00186 w_placement.rcNormalPosition.right=x+width;
00187 w_placement.rcNormalPosition.bottom=y+height;
00188
00189
00190 main_wnd->SetWindowPlacement(&w_placement);
00191 }
00192
00193 void vgui_mfc_window::set_title(const vcl_string &s)
00194 {
00195 CWinApp *app = AfxGetApp();
00196 app->GetMainWnd()->SetWindowText(s.c_str());
00197 }
00198
00199
00200 int vgui_mfc_window::set_hscrollbar(int pos)
00201 {
00202 CWnd *wnd = AfxGetApp()->GetMainWnd();
00203 return wnd->SetScrollPos(SB_HORZ, pos);
00204 }
00205
00206
00207 int vgui_mfc_window::set_vscrollbar(int pos)
00208 {
00209 CWnd *wnd = AfxGetApp()->GetMainWnd();
00210 return wnd->SetScrollPos(SB_VERT, pos);
00211 }