core/vgui/impl/win32/vgui_win32_dialog_impl.h
Go to the documentation of this file.
00001 // This is core/vgui/impl/win32/vgui_win32_dialog_impl.h
00002 #ifndef vgui_win32_dialog_impl_h_
00003 #define vgui_win32_dialog_impl_h_
00004 //:
00005 // \file
00006 // \brief The Win32 Application Programming Interfaces (API) implementation of vgui_dialog_impl.
00007 // \author Lianqing Yu
00008 // \date July 30, 2009              Initial version
00009 //
00010 // \todo TODO issues:
00011 // 1. dir_bsr, line_br are not implemented.
00012 // 2. Dialog font is not set.
00013 // 3. get_current_tab
00014 // 4. inline_file and inline_color
00015 
00016 #include <vgui/internals/vgui_dialog_impl.h>
00017 #include <vgui/impl/win32/vgui_win32_adaptor.h>
00018 #include <vgui/vgui_command.h>
00019 
00020 #include <windows.h>
00021 
00022 #define IDC_STATIC      -1
00023 #define DLG_ID_START    0x8000
00024 
00025 typedef struct tag_inline_tab_data
00026 {
00027   unsigned short     childId;
00028   HWND               hWnd;
00029   vgui_win32_adaptor *adaptor;
00030 } inline_tab_data;
00031 
00032 // Used as a search table to launch command.
00033 typedef struct tag_callback_control_data
00034 {
00035   unsigned short    child_id;
00036   vgui_command_sptr cmnd;
00037 } callback_control_data;
00038 
00039 
00040 class vgui_win32_dialog_impl : public vgui_dialog_impl
00041 {
00042  public:
00043   vgui_win32_dialog_impl(const char*, HWND hWndParent = NULL);
00044   ~vgui_win32_dialog_impl();
00045 
00046   // Overloaded virtual functions that return all kinds of widget that Win32
00047   // supports.
00048   void* pushbutton_field_widget(const char*, const void*);
00049   void* choice_field_widget(const char*, const vcl_vector<vcl_string>&, int&);
00050   void* inline_tableau_widget(const vgui_tableau_sptr tab, unsigned width, unsigned height);
00051   void modal(bool m) { is_modal = m; }
00052   bool ask();
00053   virtual void run();
00054 
00055   // Called within message processing loop for controls registered with
00056   // callback function.
00057   void dialog_dispatcher(int item_id);
00058 
00059   // Virtual message handling functions
00060   virtual LRESULT DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
00061   virtual void OnOK();
00062   virtual void OnCancel();
00063   virtual BOOL OnBrowse(HWND hDlg, WORD wCtrlId);
00064   virtual BOOL OnColor(HWND hDlg, WORD wCtrlId, LPTSTR lpColor);
00065 
00066   // Return the number of inline tableaus in the dialog.
00067   int get_inline_tableau_size() { return inline_tableaus.size(); }
00068   // Return the inline tableau with focus.
00069   // TODO: fix me.
00070   vgui_win32_adaptor* get_current_tab() { return inline_tableaus.front().adaptor; }
00071 
00072  protected:
00073   COLORREF ColorStringToRGB(LPTSTR lpColor);
00074 
00075   bool ok_clicked;
00076   bool is_modal; // dialog is modal or modaless
00077 
00078   HWND hWndParent; // application (parent) window of this dialog box,
00079                    // used to create dialog box
00080   HWND hWnd; // window handle of this dialog box.
00081 
00082  private:
00083   // Find out the size of the dialog box.
00084   void FindDialogSize(int &width, int &height,
00085                       int &max_length, int &fbsr_count,
00086                       int cxChar, int cyChar, int width_sep, int height_sep,
00087                       int button_length, int edit_length, int browser_length);
00088 
00089   // Draw an image on an owner-draw button
00090   void DrawImageOnButton(HDC hDC, RECT* lprcItem, HBITMAP hBitmap, unsigned w, unsigned h, BOOL isDisabled);
00091 
00092   // Determine if the control with identifier "ctrl_id"
00093   // is a file browser button.
00094   bool IsFileBrowserButton(unsigned short ctrl_id);
00095   // Determine if the control with identifier "ctrl_id"
00096   // is a color chooser button.
00097   bool IsColorChooserButton(unsigned short ctrl_id);
00098   // Determine if the control with identifier "ctrl_id"
00099   // has a callback function with it.
00100   bool IsCallbackControl(unsigned short ctrl_id);
00101 
00102   // Find the inline adaptor with identifier "ctrl_id".
00103   vgui_win32_adaptor* find_adaptor(unsigned short ctrl_id);
00104 
00105   // Save information of all inline tableaus added in the dialog box.
00106   vcl_vector<inline_tab_data> inline_tableaus;
00107 
00108   // Save identifiers of file-browser/color-chooser buttons so that
00109   // OnBrowse/OnColor are called when these buttons are clicked.
00110   vcl_vector<unsigned short> fb_ids, cc_ids;
00111 
00112   // Save identifiers of all controls that connect to a callback function.
00113   vcl_vector<callback_control_data> callback_controls;
00114 };
00115 
00116 
00117 #endif // vgui_win32_dialog_impl_h_