doc_and_tools/tools/apps/hg-helper/DlgBase.h

146 lines
4.7 KiB
C++

#pragma once
#include <Windows.h>
#include <CommCtrl.h>
#include <string>
#include <vector>
#include <sane/sane_ex.h>
#include <sane/sane_option_definitions.h>
// CDlgIndicator 对话框
#define FLOAT_FORMAT L"%.2f"
#define IS_STR_EQUAL(s1, s2) (wcscmp(s1, s2) == 0)
#define IS_EDIT(cls) IS_STR_EQUAL(cls, WC_EDITW)
#define IS_COMBOX(cls) IS_STR_EQUAL(cls, WC_COMBOBOXW)
#define IS_BUTTON(cls) IS_STR_EQUAL(cls, WC_BUTTONW)
#define IS_TRACKBAR(cls) IS_STR_EQUAL(cls, TRACKBAR_CLASSW)
#define IS_UPDOWN_ARROW(cls) IS_STR_EQUAL(cls, UPDOWN_CLASSW)
#define RECT_W(r) (r.right - r.left)
#define RECT_H(r) (r.bottom - r.top)
#define WM_SCAN_WORKING WM_USER + 301 // WPARAM: unused; LPARAM: unsed
#define WM_USB_PACKET_RECEIVED WM_USER + 302
#define WM_IMAGE_RECEIVED WM_USER + 303
#define WM_SCAN_FINISHED WM_USER + 304 // WPARAM: std::string* msg; LPARAM: boo err
#define WM_REFRESH_OPTION WM_USER + 311 // WPARAM: source option SN, LPARAM: unused now
#define WM_GET_CONFIG_OBJ WM_USER + 312 // WPARAM: bool*, [in]create new if NULL; [out]created, LPARAM: to receive the gb::sane_config_schm* object
class dlg_base
{
int modal_exit_; // set non-ZERO code to exit modal dialog
protected:
HWND hwnd_;
HWND parent_;
UINT idd_;
bool abandon_hold_;
void(__stdcall* ui_event_notify_)(int uev, void* sender, void* param);
void* ui_notify_param_;
static std::wstring prop_name;
static BOOL CALLBACK dlg_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
virtual BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp);
virtual void on_font_changed(void);
void create(void);
void notify_ui_event(int ev);
public:
dlg_base(HWND parent, UINT idd);
virtual ~dlg_base();
static void screen_2_client(HWND wnd, LPRECT r);
static void client_2_screen(HWND wnd, LPRECT r);
static bool get_max_size(SIZE& dst, const SIZE& src); // return whether changed dst
static bool get_max_size(SIZE& dst, int cx, int cy); // return whether changed dst
static int select_combo_text(HWND combo, const wchar_t* text);
static std::wstring get_wnd_text(HWND h);
static bool is_language_pack_default_code_page(void);
static std::wstring get_menu_text(HMENU menu, int ind);
static void center_window(HWND wnd, HWND parent);
static int get_combox_cur_sel(HWND wnd);
static int get_button_check(HWND wnd);
static int list_insert_column(HWND list_wnd, const wchar_t* text, int cx = 20, int ind = -1);
static int list_insert_item(HWND list_wnd, const wchar_t* text, int ind = -1);
static int list_get_item_count(HWND list_wnd);
static int list_get_column_count(HWND list_wnd);
static std::wstring list_get_text(HWND list_wnd, int ind, int sub = 0);
static void list_get_selected_items(HWND list_wnd, std::vector<int>& sels);
static int list_set_item_text(HWND list_wnd, int item, int sub_item, const wchar_t* text);
static int get_tab_count(HWND tab);
static int insert_page_to_tab(HWND tab, dlg_base* page, const wchar_t* title);
static void* get_tab_item_data(HWND tab, int index);
static std::string u2m(const wchar_t* u, int page);
static std::wstring m2u(const char* m, int page);
public:
void set_ui_event_notify(void(__stdcall* notify)(int, void*, void*), void* param);
HWND hwnd(void);
void show(bool visible, bool hold = false);
int do_modal(HWND parent);
void quit_modal(int non_zero_code);
void enable(bool enable);
void screen_2_client(LPRECT r);
void client_2_screen(LPRECT r);
HWND get_item(UINT id);
BOOL set_font(HFONT font);
HFONT get_font(void);
int get_string_width(const wchar_t* str, HWND wnd = NULL);
bool get_item_rect(UINT id, LPRECT r, bool client = true);
std::wstring get_item_text(UINT id);
int get_width_diff_as_text_length(UINT id); //
void offset_item(HWND wnd, int dx, int dy);
void offset_item(UINT id, int dx, int dy);
void expand_item(UINT id, int dx, int dy);
bool set_item_text(UINT id, const wchar_t* text);
int set_item_fit_to_text(UINT id); // return difference
void show_scroll_bar(int bar = SB_VERT, bool show = true);
bool track_mouse_hover(void);
};
class tooltip_wnd
{
HWND hwnd_;
HWND parent_;
WNDPROC org_proc_;
typedef struct _tip_ele
{
HWND ctrl;
RECT rect;
std::wstring tips;
struct _tip_ele()
{
ctrl = NULL;
memset(&rect, 0, sizeof(rect));
tips = L"";
}
bool operator==(const HWND& wnd)
{
return ctrl == wnd;
}
bool operator==(const RECT& r)
{
return memcmp(&rect, &r, sizeof(r)) == 0;
}
}TIPELEM;
std::vector<TIPELEM> elements_;
public:
tooltip_wnd();
~tooltip_wnd();
public:
bool create(HWND parent);
void enable(bool enabled);
bool add_tool_tip_for_rect(const RECT& r, const wchar_t* tips);
bool add_tool_tip_for_ctrl(HWND ctrl, const wchar_t* tips);
bool remove_tool_tip_for_ctrl(HWND ctrl);
};