core/vgui/impl/win32/vgui_win32_window.h
Go to the documentation of this file.
00001 // This is core/vgui/impl/win32/vgui_win32_window.h
00002 #ifndef vgui_win32_window_h_
00003 #define vgui_win32_window_h_
00004 //:
00005 // \file
00006 // \brief The Win32 Application Programming Interfaces (API) implementation of vgui_window.
00007 // \author Lianqing Yu
00008 // \date   July 30, 2009
00009 //
00010 // Modifications:
00011 // July 30, 2009              Initial version
00012 
00013 
00014 #include <vgui/vgui_window.h>
00015 #include <vgui/impl/win32/vgui_win32_adaptor.h>
00016 #include <vgui/impl/win32/vgui_win32_statusbar.h>
00017 #include <vgui/impl/win32/vgui_win32_cmdtarget.h>
00018 
00019 #include <windows.h>
00020 
00021 class vgui_win32_window : public vgui_window, public vgui_win32_cmdtarget
00022 {
00023  public:
00024   // Constructors. application instance handle and name are required
00025   // to create a window in Win32 programming.
00026   vgui_win32_window(HINSTANCE hInst, const char *appname, int width,
00027                     int height, vgui_menu const &menubar, char const *title);
00028   vgui_win32_window(HINSTANCE hInst, const char *appname, int width,
00029                     int height, char const *title);
00030   ~vgui_win32_window();
00031 
00032   // Public functions for accessing members.
00033   HWND getWindowHandle() { return hwnd_; }
00034   HACCEL getAccelHandle() { return hAccel_; }
00035 
00036  //: Put the given menu in the menubar (if it exists).
00037   virtual void set_menubar(vgui_menu const &);
00038 
00039   //: If true, activate the statusbar (if it exists).
00040   virtual void set_statusbar(bool);
00041 
00042   //: Set the default adaptor (if it exists) to the given vgui_adaptor.
00043   //  These refer to the default/current adaptor, if that makes
00044   //  sense. It is not a requirement that it should make sense.
00045   virtual void set_adaptor(vgui_adaptor *adaptor) { /*adaptor_ = adaptor;*/ }
00046 
00047 
00048   //: Get the default adaptor (if it exists).
00049   virtual vgui_adaptor *get_adaptor() { return adaptor_; }
00050 
00051   //: Get the status bar (if it exists).
00052   // \todo This function is not called yet.
00053   virtual vgui_statusbar *get_statusbar() { return statusbar_; }
00054 
00055 
00056   //: Display the window.
00057   virtual void show();
00058 
00059   //: Hide the window from view.
00060   // \todo This function is not called yet.
00061   virtual void hide() { ShowWindow(hwnd_, SW_HIDE); }
00062 
00063   //: Turn the window into an icon.
00064   // \todo This function is not called yet.
00065   virtual void iconify() { ShowWindow(hwnd_, SW_MINIMIZE); }
00066 
00067   //: If true, activate horizontal scrollbar (if it exists).
00068   virtual void enable_hscrollbar(bool);
00069 
00070   //: If true, activate vertical scrollbar (if it exists).
00071   virtual void enable_vscrollbar(bool);
00072 
00073   //: Change window shape to new given width and height.
00074   virtual void reshape(unsigned, unsigned);
00075 
00076   //: Move the window to the new given x,y position.
00077   virtual void reposition(int, int);
00078 
00079   //: Use the given text as the window title (if the window has a title).
00080   // \todo This function is not called yet.
00081   virtual void set_title(vcl_string const &t) { SetWindowText(hwnd_, t.c_str()); }
00082 
00083   //: Set the position of the horizontal scrollbar, returns old position
00084   virtual int set_hscrollbar(int pos);
00085 
00086   //: Set the position of the vertical scrollbar, returns old position
00087   virtual int set_vscrollbar(int pos);
00088 
00089   // Message handling function
00090   virtual LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
00091   virtual LRESULT DefWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
00092   virtual BOOL OnCmdMsg(UINT message, WPARAM wParam, LPARAM lParam);
00093   // Called within message processing loop.
00094   void menu_dispatcher(int menuId);
00095 
00096 #if 0
00097   void OnCreate();
00098   void OnClose();
00099   void OnTimer();
00100 #endif
00101 
00102  protected:
00103   HWND  hwnd_;  //!< application window handle
00104   HMENU hMenu_; //!< application menu handle
00105   HACCEL hAccel_; // accelerator handle
00106   vcl_vector<vgui_command_sptr> callbacks; //!< commands called by menu items
00107 
00108  private:
00109   // Create window and initialize class members.
00110   void initWindow(HINSTANCE hInst, const char *appname, int width,
00111                   int height, char const *title);
00112 
00113   vgui_win32_adaptor *adaptor_;
00114   vgui_win32_statusbar *statusbar_;
00115 
00116   int      wx_, wy_; //!< window position (wx, wy)
00117   unsigned cx_, cy_; //!< and client area size (cx, cy).
00118   bool first_show;   //!< indicate if the member function show()
00119                      //!< is called for the first time
00120 
00121   DECLARE_MESSAGE_MAP()
00122 };
00123 
00124 #endif // vgui_win32_window_h_