⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgwidget.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * $Id: mgwidget.cpp,v 1.3 2002/01/29 10:14:45 ymwei Exp $ * * This file is a part of Monqueror. *  * mgwidget.cpp: widget implementation of MiniGUI. */#define WIDGET_DEBUG 0#include <stdio.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <assert.h>#include "render_interface.h"#include "mghtmlview.h"#include "kdebug.h"#include "kurl.h"#include "dom_nodeimpl.h"#include "dom_textimpl.h"#include "dom_docimpl.h"#include "html_formimpl.h"#include "html_documentimpl.h"#include "htmlhashes.h"#include "render_form.h"int MG::g_nChildWndID = 0x100;using namespace khtml;MGWidget::MGWidget (){#if WIDGET_DEBUG	fprintf(stderr, "MGWidget::MGWidget\n");#endif	m_hWnd = HWND_INVALID;}MGWidget::MGWidget (HWND hWndParent, RenderFormElement * renderer){#if WIDGET_DEBUG	fprintf(stderr, "MGWidget::MGWidget(HWND hWndParent)\n");#endif	m_hWnd = HWND_INVALID;	m_hWndParent = hWndParent;	m_renderer = renderer;}MGWidget::~MGWidget(){	//DestroyWindow( m_hWnd );	}	HDC MGWidget::getHdc () const{ 	/* FIXME: When you will release this DC? */	return GetDC (m_hWnd);	}#if 0int MGWidget::ProcNotification (int code){	/* FIXME: MGWidget is a base class. You do not know	   this specific class of control, 	   so what does the code mean?	 */	switch (code){	case 4:	// What is "4"?	case BN_CLICKED:		clicked ();		break;	}	return 0;}#endifvoid MGWidget::clicked(){	m_renderer -> slotClicked();}void MGWidget::initWindow(){#if WIDGET_DEBUG	fprintf(stderr, "MGWidget::initWindow\n");#endif}//---------------------------------------------------------------------------------------int MGWidget::width() const{	assert (m_hWnd != (HWND) HWND_INVALID);	RECT rect;	GetWindowRect (m_hWnd, &rect);	return rect.right-rect.left+1;}int MGWidget::height() const{	assert (m_hWnd != (HWND) HWND_INVALID);	RECT rect;	GetWindowRect (m_hWnd, &rect);	return rect.bottom-rect.top+1;}int MGWidget::x() const{	assert( m_hWnd != ( HWND ) HWND_INVALID );	RECT rect;	GetWindowRect( m_hWnd, &rect );	return rect.left;}int MGWidget::y() const{	assert( m_hWnd != ( HWND ) HWND_INVALID );	RECT rect;	GetWindowRect( m_hWnd, &rect );	return rect.top;}void MGWidget::show(){	assert( m_hWnd != ( HWND ) HWND_INVALID );	ShowWindow( m_hWnd, SW_SHOW );}void MGWidget::hide(){	assert( m_hWnd != ( HWND ) HWND_INVALID );	ShowWindow( m_hWnd, SW_HIDE );}void MGWidget::resize( int w, int h ){	m_rectWnd.setWidth( w );	m_rectWnd.setHeight( h );}void MGWidget::moveWindow( int x, int y ){	int w = m_rectWnd.width();	int h = m_rectWnd.height();	m_rectWnd.setLeft( x );	m_rectWnd.setTop( y );	m_rectWnd.setWidth( w );	m_rectWnd.setHeight( h );	MoveWindow (m_hWnd, x, y, m_rectWnd.width(), m_rectWnd.height(), false); }void MGWidget::setFont( const MGFont& font ){	// TODO}void MGWidget::setFocus(){	// TODO}void MGWidget::clearFocus(){	// TODO}MGSize MGWidget::sizeHint() const{	// TODO		return MGSize (80, GetSysCharHeight () + 8);}void MGWidget::setText( const char * str ){	if (!str) str = "";	    SendMessage(m_hWnd, MSG_SETTEXT, 0, (LPARAM)str);}void MGWidget::layout(){}// ----------------- Button ------------------------MGWidgetButton::MGWidgetButton(HWND hWndParent, RenderFormElement * renderer)			:MGWidget(hWndParent, renderer){	initWindow ();}MGWidgetButton::~MGWidgetButton(){}MGSize MGWidgetButton::sizeHint() const{	int text_len = GetWindowTextLength (m_hWnd);	return MGSize (text_len * GetSysCharWidth () + 16, GetSysCharHeight () + 10);}void MGWidgetButton::clicked(){	m_renderer -> slotClicked();}void MGWidgetButton::initWindow(){	m_hWnd = ::CreateWindow ("button",				"",				WS_CHILD,				MG::g_nChildWndID++,				0, 0, 1, 1,				m_hWndParent, (DWORD)this);//	You can set additional data by passing it in CreateWindow.//	SetWindowAdditionalData( m_hWnd,(DWORD) this);}//----------------- Radio ----------------------------MGWidgetRadio::MGWidgetRadio(HWND hWndParent, RenderFormElement * renderer)			: MGWidget(hWndParent, renderer){	initWindow();}MGWidgetRadio::~MGWidgetRadio(){}MGSize MGWidgetRadio::sizeHint() const{	return MGSize( 15, 14);}void MGWidgetRadio::clicked(){	m_renderer -> slotClicked();}void MGWidgetRadio::setChecked(bool b){	if (b)		SendMessage(m_hWnd, BM_SETCHECK, 1, 0);	else		SendMessage(m_hWnd, BM_SETCHECK, 0, 0);}void MGWidgetRadio::initWindow(){	static QString pre_name = "";	QString cur_name;	cur_name = ( m_renderer -> element() -> name() ) . string();	if ( cur_name != pre_name){		m_hWnd = ::CreateWindow( "button",					"",					WS_CHILD | BS_AUTORADIOBUTTON | WS_GROUP,					MG::g_nChildWndID++,					0, 0, 1, 1,					m_hWndParent, (DWORD) this);		pre_name = cur_name;	}	else{		m_hWnd = ::CreateWindow( "button",					"",					WS_CHILD | BS_AUTORADIOBUTTON,					MG::g_nChildWndID++,					0, 0, 1, 1,					m_hWndParent, (DWORD) this);	}//	SetWindowAdditionalData( m_hWnd,(DWORD) this);}//---------------------- CheckBox ---------------------------------MGWidgetCheck::MGWidgetCheck(HWND hWndParent, RenderFormElement * renderer)			: MGWidget(hWndParent, renderer){	initWindow();}MGWidgetCheck::~MGWidgetCheck(){}MGSize MGWidgetCheck::sizeHint() const{	return MGSize( 15, 14);}void MGWidgetCheck::clicked(){	SendMessage (m_hWnd, BM_SETCHECK, !SendMessage (m_hWnd, BM_GETCHECK, 0, 0L), 0L);	static_cast<RenderCheckBox*>(m_renderer) -> slotStateChanged(2);	MGWidget::clicked();}void MGWidgetCheck::setChecked(bool b){	if (b)		SendMessage(m_hWnd, BM_SETCHECK, 1, 0);	else		SendMessage(m_hWnd, BM_SETCHECK, 0, 0);}void MGWidgetCheck::initWindow(){	m_hWnd = ::CreateWindow( "button",				"",				WS_CHILD | BS_AUTOCHECKBOX,				MG::g_nChildWndID++,				0, 0, 1, 1,				m_hWndParent, (DWORD)this);//	SetWindowAdditionalData( m_hWnd,(DWORD) this);}//--------------------------- LineEdit -------------------------------MGWidgetEdit::MGWidgetEdit(HWND hWndParent, RenderFormElement * renderer) : MGWidget(hWndParent, renderer){	initWindow();}MGWidgetEdit::~MGWidgetEdit(){}int MGWidgetEdit::ProcNotification (int code){	switch (code) {	case EN_CHANGE:	{		/* FIXME: Why you can sure that text is 50 characters long? */		char buf[50];		memset(buf, '\0', 50);			GetWindowText(m_hWnd, buf, 50);			QString str(buf);			static_cast<RenderLineEdit *>(m_renderer)->slotTextChanged(str);		break;	}	return code;	}	return 0;}void MGWidgetEdit::clicked(){	setFocus();	//MessageBox(m_hWndParent, "MGWidgetEdit111", "MGWidgetEdit222", MB_OK);	//(RenderCheckBox *)m_renderer -> slotStateChanged(2);}void MGWidgetEdit::initWindow(){	m_hWnd = ::CreateWindow ("edit",				"",				WS_CHILD | WS_BORDER,				MG::g_nChildWndID++,				0, 0, 1, 1,				m_hWndParent, (DWORD) this);//	SetWindowAdditionalData (m_hWnd, (DWORD) this);}//----------------------- Password ------------------------------MGWidgetEditPassword::MGWidgetEditPassword(HWND hWndParent, RenderFormElement * renderer)			: MGWidgetEdit(hWndParent, renderer){	initWindow();}MGWidgetEditPassword::~MGWidgetEditPassword(){}void MGWidgetEditPassword::initWindow(){	m_hWnd = ::CreateWindow ("edit",				"",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -