Fail API wrapper class, I need criticism..
As some of you may know I recently started programming on Ubuntu.. well, not that you guys care anyway.
So, I come here to post my fail wrapper for the GTK+ class... Well it's not even a fail, it's less than that because it isn't finished and I'm not really ready for it yet, the I tried setting up a single callback for every widget and I failed hardcore so I'm putting this on pause for a bit.
Also, the reason I was making this wrapper was because GTK+ is fucking disgusting... I know I'm going to get flamed cause I know that Linux is the superior programming OS, as some say.. I'm just too much of a Windows fanboy to possibly like the way they set up the GTK library, just the names of the functions is enough to make me puke..
Anyway, posting this 'cause I would like some suggestions on how I could improve on the parts I've already done, anything at all, anything to make the class easier to use.
How I was originally going to do it was... a little like this...
Main class -> Widget class -> Seperate class for each widget.
But that obviously didn't work out, kind of.. I just didn't add the other classes to the widget class, and I didn't make them all, yet.. I didn't even make the main class yet, I was working backwards..
CWidget.h
[php]
#ifndef CWIDGET_H
#define CWIDGET_H
#include <gtk/gtk.h>
#include "CMenu.h"
enum WidgetType { WT_BUTTON = 0,
WT_LABEL,
WT_CHECKBUTTON,
WT_MENU,
WT_CHILD
};
class CWidget {
private:
static GtkWidget* PlacementFrame;
GtkWidget* Widget;
WidgetType Type;
public:
static void InitializeWidget(GtkWidget*);
void CreateWidget(WidgetType,char*,int,int,int,int);
void SetText(char*);
};
#endif
[/php]
CWidget.cpp
[php]
#include "CWidget.h"
GtkWidget* CWidget::PlacementFrame = NULL;
void CWidget::InitializeWidget(GtkWidget* pf)
{
CWidget::PlacementFrame = pf;
}
void CWidget::CreateWidget(WidgetType Type,char* text,int Width,int Height,int X,int Y)
{
switch(Type)
{
case WT_BUTTON:
CWidget::Widget = gtk_button_new_with_label(text);
gtk_widget_set_size_request(CWidget::Widget,Width, Height);
gtk_fixed_put(GTK_FIXED(PlacementFrame),CWidget::W idget,X,Y);
CWidget::Type = WT_BUTTON;
break;
case WT_LABEL:
CWidget::Widget = gtk_label_new(text);
gtk_fixed_put(GTK_FIXED(PlacementFrame),CWidget::W idget,X,Y);
CWidget::Type = WT_LABEL;
break;
}
}
void CWidget::SetText(char* text)
{
switch(CWidget::Type)
{
case WT_BUTTON:
gtk_button_set_label((GtkButton*)CWidget::Widget,t ext);
break;
case WT_LABEL:
gtk_label_set_text((GtkLabel*)CWidget::Widget,text );
break;
}
}
[/php]
CCheckButton.h
[php]
#ifndef CCHECKBUTTON_H
#define CCHECKBUTTON_H
#include <gtk/gtk.h>
class CCheckButton {
private:
GtkWidget* CheckButton;
public:
void CreateCheckButton(GtkWidget* Place,char*,int,int,bool);
bool GetStatus();
void SetStatus(bool);
};
#endif
[/php]
CCheckButton.cpp
[php]
#include "CCheckButton.h"
void CCheckButton::CreateCheckButton(GtkWidget* Place,char* text,int X,int Y,bool active)
{
CCheckButton::CheckButton = gtk_check_button_new_with_label(text);
GTK_WIDGET_UNSET_FLAGS(CCheckButton::CheckButton,G TK_CAN_FOCUS);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(CCh eckButton::CheckButton),active);
gtk_fixed_put(GTK_FIXED(Place),CCheckButton::Check Button,X,Y);
}
bool CCheckButton::GetStatus()
{
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(CCh eckButton::CheckButton));
}
void CCheckButton::SetStatus(bool active)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(CCh eckButton::CheckButton),active);
}
[/php]
CMenu.h
[php]
#ifndef CMENU_H
#define CMENU_H
#include <gtk/gtk.h>
class CMenu {
private:
GtkWidget* Placement;
GtkWidget* MenuBar;
GtkWidget* MenuItem[128];
public:
void CreateMenu(GtkWidget*,int,int);
void AddMenuSelection(char*,int);
void AddMenuItem(char*,int);
};
#endif
[/php]
CMenu.cpp
[php]
#include "CMenu.h"
void CMenu::CreateMenu(GtkWidget* Place,int X,int Y)
{
CMenu::MenuBar = gtk_menu_bar_new();
gtk_fixed_put(GTK_FIXED(Place),CMenu::MenuBar,X,Y) ;
}
void CMenu::AddMenuSelection(char* text,int index)
{
CMenu::MenuItem[index] = gtk_menu_new();
GtkWidget* ItemName = gtk_menu_item_new_with_label(text);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(ItemName), CMenu::MenuItem[index]);
gtk_menu_shell_append(GTK_MENU_SHELL(CMenu::MenuBa r),ItemName);
}
void CMenu::AddMenuItem(char* item,int index)
{
GtkWidget* Item = gtk_menu_item_new_with_label(item);
gtk_menu_shell_append(GTK_MENU_SHELL(CMenu::MenuIt em[index]),Item);
}
[/php]
And here's an example of how to use it... You may have noticed there is some GTK API in the main file, as I said, the main class is not complete so I had to create the placement frame and the actual window using the actual GTK API..
Main.cpp
[php]
#include <gtk/gtk.h>
#include "CWidget.h"
#include "CCheckButton.h"
CWidget* Button;
CCheckButton* CheckButton;
CMenu *Menu;
int main()
{
GtkWidget* MainWindow;
GtkWidget* cPlacementFrame;
gtk_init(NULL,NULL);
MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(MainWindow) ,300,300);
cPlacementFrame = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(MainWindow),cPlace mentFrame);
CWidget::InitializeWidget(cPlacementFrame);
//Button
Button = new CWidget;
Button->CreateWidget(WT_BUTTON,"Button",85,50,30,30);
//CheckButton
CheckButton = new CCheckButton;
CheckButton->CreateCheckButton(cPlacementFrame,"Check button",30,80,false);
//Menu
Menu = new CMenu;
Menu->CreateMenu(cPlacementFrame,0,0);
Menu->AddMenuSelection("File",1);
Menu->AddMenuItem("New",1);
Menu->AddMenuItem("Open",1);
Menu->AddMenuItem("Quit",1);
gtk_widget_show_all(MainWindow);
gtk_main();
return 0;
}
[/php]
Remember, I want suggestions on how to make it better. Also, your opinion on the structure of everything..