Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / MFC

Be Sweet - a set of visual source code browsers

Rate me:
Please Sign up or sign in to vote.
4.85/5 (35 votes)
1 Jul 20038 min read 183.7K   4.9K   122  
A set of source code and project browsers to compliment Visual Studio.
/**
/*   Copyright (c) 2003by  Marco Welti
/*
/*   This document is  bound by the  QT Public License
/*   (http://www.trolltech.com/licenses/qpl.html).
/*   See License.txt for more information.
/*
/*
/*
/*   ALL RIGHTS RESERVED.  
/* 
/*   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
/*   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
/*   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
/*   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
/*   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
/*   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
/*   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
/*   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
/*   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
/*   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
/*   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* 
/***********************************************************************/

#ifndef CustomDialog_H
#define CustomDialog_H

#include <vector>
#include "smart_ptr.h"

#include "ResizingDialog.h"
#include "MouseEventDispatcher.h"
#include "Properties.h"

class NCButton {
public:
	typedef enum { eFlat = 0, eActive, eSunken } ButtonState;

private:
	ButtonState mState;
	smart_ptr<CBitmap> mImages[3];

	CPoint mPos;
	CSize mSize;
	bool mIsCheckbox;

public:
	NCButton() : mState(eFlat) {}

	NCButton(size_t f, size_t a, size_t s);
	~NCButton();

	CBitmap* getImage() { return mImages[mState].get(); }

	bool isCheckbox() { return mIsCheckbox; }

	ButtonState getState() const { return mState; }
	void setState(ButtonState s) { mState = s; }

	const CPoint& getPos() const { return mPos; };
	void setPos(const CPoint &pos) { mPos = pos; };

	const CSize& getSize() const { return mSize; };
	void setPos(const CSize &size) { mSize = size; };
};

class CustomDialog : public CDialog
{
private:
  std::vector<NCButton> mButtons;
  bool mIsMouseButtonDown;
	const static size_t FRAME_SIZE;

public:
  CustomDialog(ULONG dialogID, CWnd* pParent = NULL);
	virtual void mouseAt(CPoint&) = 0;

protected:
	NCButton& getButton(CPoint);
	CRect getCaptionRect();

  //{{AFX_MSG(CTemplateDlg)
	afx_msg void OnNcPaint();
	afx_msg UINT OnNcHitTest(CPoint point);
	afx_msg void OnNcLButtonDown( UINT nHitTest, CPoint point );
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()


};


class RaisableDialog : public MouseEventDispatcher<CResizingDialog>, public MouseListener
{
public:
  typedef enum{TOPLEFT=0, TOPRIGHT, BOTTOMLEFT, BOTTOMRIGHT } Corner;
  
private:
  typedef MouseEventDispatcher<CResizingDialog> super;

  HWND mCoveredBy;
  std::string mCaption;

  std::string mHoverTimeKey;
  std::string mRaiseCornerKey;
  std::string mPositionKey;

  CWnd *mFocusableWindow;
  HICON mIcon;

public:
  RaisableDialog(UINT id, CWnd* parent = NULL);

  void moveToForeground();
  void moveToBackground();

  virtual void show(bool modal = false);
  virtual void hide();
  virtual void close();
  
  virtual void setCaption(const std::string&);
  virtual std::string getCaption();

  virtual void setPosition(short x, short y);
  virtual std::pair<short, short> getPosition();

  void setRaiseCornerKey(const std::string &key) { mRaiseCornerKey = key; }
  void setHoverTimeKey(const std::string &key) { mHoverTimeKey = key; }
  void setPositionKey(const std::string &key) { mPositionKey = key; }
  void setFocusableWindow(CWnd *wnd) { mFocusableWindow = wnd; }
  void setIcon(UINT id);

protected:
  virtual long getHoverTime();

  void mouseHovering(const MouseEvent&);
  void mouseExited(const MouseEvent&);

  afx_msg void OnClose();
  afx_msg void OnShowWindow(BOOL, UINT);
  BOOL OnInitDialog();
  DECLARE_MESSAGE_MAP()

private:
  CPoint getRaiseCorner();
  bool isInForeground();  

};
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions