/*
Copyright (C) 2006 Evan Teran
                   eteran@alum.rit.edu

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef QDISASSEMBLYVIEW_20061101_H_
#define QDISASSEMBLYVIEW_20061101_H_

#include <QAbstractScrollArea>
#include <QPixmap>

#include "MemoryRegions.h"
#include "types.h"

class QDisassemblyView : public QAbstractScrollArea {
	Q_OBJECT
		
public:
	QDisassemblyView(QWidget *parent = 0);
	virtual ~QDisassemblyView();
	
public:
	typedef BaseTypes::address_t address_t;
	
protected:
	virtual void paintEvent(QPaintEvent *event);
	virtual void mouseDoubleClickEvent(QMouseEvent *event);

public:
	bool addressShown(address_t address);

public slots:
	void setFont(const QFont &f);
	void resizeEvent(QResizeEvent *event);
	void scrollTo(address_t address);
	void setAddressOffset(address_t address);
	void setRegion(const MemoryRegions::Region &r);
	void setCurrentAddress(address_t address);
	void clear();
	
signals:
	// has to be BaseTypes version so it matches slot in DebuggerMain.cpp
	void breakPointToggled(BaseTypes::address_t address);

private:
	static int getInstructionSize(uint8_t *buffer, std::size_t size);

private:
	void updateScrollbars();
	int line1() const;
	int line2() const;
	int addressLen() const;
	QString formatAddress(address_t address);
	
private:
	address_t				m_FirstVisibleAddress;
	address_t				m_LastVisibleAddress;
	address_t				m_AddressOffset;
	address_t	 			m_CurrentAddress;
	int						m_FontWidth;	// width of a character in this font
	int						m_FontHeight;	// height of a character in this font
	QPixmap					m_Breakpoint;
	QPixmap					m_CurrentAddressIcon;
	bool					m_ShowAddressSeparator;
	int						m_LongestInstr;
	MemoryRegions::Region	m_Region;
	char					m_AddressFormatString[32];
};

#endif
