// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2010 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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, see .
*
* Authored by: Mirco Müller
* Authored by: Jay Taoko
*/
#ifndef QUICKLISTMENUITEM_H
#define QUICKLISTMENUITEM_H
#include
#include
#include "Nux/Nux.h"
#include "Nux/View.h"
#include "NuxImage/CairoGraphics.h"
#include
#include
#include "Introspectable.h"
#define ITEM_INDENT_ABS 16
#define ITEM_CORNER_RADIUS_ABS 3
#define ITEM_MARGIN 4
typedef enum
{
MENUITEM_TYPE_UNKNOWN = 0,
MENUITEM_TYPE_LABEL,
MENUITEM_TYPE_SEPARATOR,
MENUITEM_TYPE_CHECK,
MENUITEM_TYPE_RADIO,
} QuicklistMenuItemType;
class QuicklistMenuItem : public nux::View, public Introspectable
{
public:
QuicklistMenuItem (DbusmenuMenuitem* item,
NUX_FILE_LINE_PROTO);
QuicklistMenuItem (DbusmenuMenuitem* item,
bool debug,
NUX_FILE_LINE_PROTO);
virtual ~QuicklistMenuItem ();
void PreLayoutManagement ();
long PostLayoutManagement (long layoutResult);
long ProcessEvent (nux::IEvent& event,
long traverseInfo,
long processEventInfo);
void Draw (nux::GraphicsEngine& gfxContext,
bool forceDraw);
void DrawContent (nux::GraphicsEngine& gfxContext,
bool forceDraw);
void PostDraw (nux::GraphicsEngine& gfxContext,
bool forceDraw);
QuicklistMenuItemType GetItemType ();
void ItemActivated ();
sigc::signal sigChanged;
sigc::signal sigTextChanged;
sigc::signal sigColorChanged;
virtual const gchar* GetLabel ();
virtual bool GetEnabled ();
virtual bool GetActive ();
virtual bool GetVisible ();
// Introspection
const gchar* GetName ();
void AddProperties (GVariantBuilder *builder);
protected:
gchar* _text;
nux::Color _textColor;
int _pre_layout_width;
int _pre_layout_height;
nux::CairoGraphics* _cairoGraphics;
nux::BaseTexture* _normalTexture[2];
nux::BaseTexture* _prelightTexture[2];
//! Return the size of the text + size of associated radio button or check box
void GetTextExtents (int &width, int &height);
void GetTextExtents (const gchar* font, int& width, int& height);
virtual void UpdateTexture () = 0;
virtual int CairoSurfaceWidth () = 0;
void RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags);
void RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags);
void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
void RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags);
void RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
sigc::signal sigMouseEnter;
sigc::signal sigMouseLeave;
sigc::signal sigMouseReleased;
sigc::signal sigMouseClick;
sigc::signal sigMouseDrag;
DbusmenuMenuitem* _menuItem;
QuicklistMenuItemType _item_type;
nux::Color _color; //!< Item rendering color factor.
bool _debug;
bool _prelight; //!< True when the mouse is over the item.
void DrawRoundedRectangle (cairo_t* cr,
double aspect,
double x,
double y,
double cornerRadius,
double width,
double height);
void DrawText (cairo_t* cr,
int width,
int height,
nux::Color color);
// Introspection
gchar *_name;
friend class QuicklistView;
};
#endif // QUICKLISTMENUITEM_H