Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FbMenu.cpp « MyRuLib « sources - github.com/lintest/myrulib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e14b699fd4748e144e6e8c95bdde03b0f5cef366 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "FbMenu.h"
#include "FbConst.h"
#include "FbDatabase.h"

//-----------------------------------------------------------------------------
//  FbMenu
//-----------------------------------------------------------------------------

wxMenuItem * FbMenu::AppendSub(Type type, int code, const wxString& name, const wxString& help, wxItemKind kind)
{
	wxMenuItem * item = new FbMenuItem(this, type, code, name, help, kind);
	return Append(item);
}

//-----------------------------------------------------------------------------
//  FbMenuItem
//-----------------------------------------------------------------------------

FbMenuHash FbMenuItem::m_hash;

wxWindowID FbMenuItem::NewId(FbMenu::Type type, int code)
{
	wxWindowID id = wxNewId();
	FbMenuData & data = m_hash[id];
	data.code = code;
	data.type = type;
	return id;
}

bool FbMenuItem::Get(wxWindowID id, FbMenu::Type & type, int & code)
{
	bool ok = m_hash.count(id);
	if (ok) {
		FbMenuData & data = m_hash[id];
		type = data.type;
		code = data.code;
	}
	return ok;
}

FbMenuItem::FbMenuItem(wxMenu * menu, FbMenu::Type type, int code, const wxString& name, const wxString& help, wxItemKind kind, wxMenu * submenu )
	: wxMenuItem(menu, NewId(type, code), name, help, kind, submenu)
{
}

FbMenuItem::~FbMenuItem()
{
	m_hash.erase(GetId());
}

//-----------------------------------------------------------------------------
//  FbMenuSort
//-----------------------------------------------------------------------------

FbMenuSort::FbMenuSort()
{
	AppendRadioItem(wxID_VIEW_SORTNAME, _("Title"));
	AppendRadioItem(ID_ORDER_AUTHOR,    _("Author"));
	AppendRadioItem(ID_ORDER_RATING,    _("Rating"));
	AppendRadioItem(ID_ORDER_LANG,      _("Language"));
	AppendRadioItem(wxID_VIEW_SORTTYPE, _("Extension"));
	AppendRadioItem(wxID_VIEW_SORTSIZE, _("Size"));
	AppendRadioItem(wxID_VIEW_SORTDATE, _("Date"));
	AppendSeparator();
	AppendCheckItem(ID_DIRECTION, _("Reverse order"));
}

//-----------------------------------------------------------------------------
//  FbMenuRating
//-----------------------------------------------------------------------------

FbMenuRating::FbMenuRating()
{
	for (int i=5; i>0; i--) Append(ID_RATING_0 + i, GetRatingText(i));
	AppendSeparator();
	Append(ID_RATING_0, GetRatingText(0));
}

//-----------------------------------------------------------------------------
//  FbMenuRefs
//-----------------------------------------------------------------------------

wxMenuItem * FbMenuRefs::Create(wxMenu * menu)
{
	FbCommonDatabase database;
	if (!database.TableExists(wxT("tables"))) return NULL;

	FbMenu * submenu = NULL;

	wxString sql = wxT("SELECT id, title FROM tables ORDER BY 2");
	wxSQLite3ResultSet res = database.ExecuteQuery(sql);
	while (res.NextRow()) {
		if (!submenu) submenu = new FbMenuRefs();
		submenu->AppendSub(FbMenu::CLSS, res.GetInt(0), res.GetString(1));
	}
	return submenu ? new wxMenuItem(menu, ID_FRAME_CLSS, _("Classifiers"), wxEmptyString, wxITEM_NORMAL, submenu) : NULL;
}