ObjGUI  Check-in [9ca591f16a]

Overview
Comment:Initial OGComboBox implementation.
Only support for text so far.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9ca591f16a14f102a28e03a04ab4fa87fe83a1a264148eaed9d9708a77b327c1
User & Date: js on 2011-12-28 19:23:01
Other Links: manifest | tags
Context
2012-01-05
01:00
Add copyright and a license. check-in: ef4637f824 user: js tags: trunk
2011-12-28
19:23
Initial OGComboBox implementation.
Only support for text so far.
check-in: 9ca591f16a user: js tags: trunk
2011-12-27
22:38
Make it possible to have implementations in different toolkits.
Also, make it possible to share the headers.
check-in: 31af425497 user: js tags: trunk
Changes

Added gtk/OGComboBox.m version [6c5002b205].





























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#import "OGComboBox.h"

@interface OGComboBox ()
- (void)OG_changed;
@end

static void
changed(GtkWidget *widget, gpointer data)
{
	[(OGComboBox*)data OG_changed];
}

@implementation OGComboBox
@synthesize delegate;

+ comboBox
{
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];

	widget = gtk_combo_box_new();
	GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, FALSE);
	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer,
	    "text", 0, NULL);
	g_signal_connect(G_OBJECT(widget), "changed", G_CALLBACK(changed),
	    self);

	g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(og_destroy),
	    self);
	[self retain];

	return self;
}

- (id <OGComboBoxDataSource>)dataSource
{
	return dataSource;
}

- (void)setDataSource: (id <OGComboBoxDataSource>)dataSource_
{
	GtkListStore *listStore = gtk_list_store_new(1, G_TYPE_STRING);
	GtkTreeIter iter;
	OGComboBoxItem* (*itemAtIndex)(id, SEL, OGComboBox*, size_t);

	dataSource = dataSource_;
	itemAtIndex = (OGComboBoxItem*(*)(id, SEL, OGComboBox*, size_t))
	    [dataSource methodForSelector: @selector(comboBox:itemAtIndex:)];

	size_t i, size = [dataSource numberOfItemsInComboBox: self];
	for (i = 0; i < size; i++) {
		OGComboBoxItem *item = itemAtIndex(dataSource,
		    @selector(comboBox:itemAtIndex:), self, i);

		gtk_list_store_append(listStore, &iter);
		gtk_list_store_set(listStore, &iter, 0,
		    [item.label UTF8String], -1);
	}

	gtk_combo_box_set_model(GTK_COMBO_BOX(widget),
	    GTK_TREE_MODEL(listStore));
}

- (void)OG_changed
{
	OFAutoreleasePool *pool = [OFAutoreleasePool new];

	if ([delegate respondsToSelector: @selector(comboBoxWasChanged:)])
		[delegate comboBoxWasChanged: self];

	[pool release];
}
@end

Added gtk/OGComboBoxItem.m version [da657c193d].































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#import "OGComboBoxItem.h"

@implementation OGComboBoxItem
@synthesize label;

+ comboBoxItemWithLabel: (OFString*)label
{
	return [[[self alloc] initWithLabel: label] autorelease];
}

- initWithLabel: (OFString*)label_
{
	self = [super init];

	@try {
		label = [label_ copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[label release];

	[super dealloc];
}
@end

Modified headers/OGBox.h from [8a7b04865c] to [b25b557328].

1
2
3
4
5
6
7
8
9
10
11
12
#import "OGWidget.h"

@interface OGBox: OGWidget
+ box;

- (void)appendChild: (OGWidget*)child
	     expand: (BOOL)expand
	       fill: (BOOL)fill
	    padding: (float)padding;
- (void)prependChild: (OGWidget*)child
	      expand: (BOOL)expand
		fill: (BOOL)fill




<







1
2
3
4

5
6
7
8
9
10
11
#import "OGWidget.h"

@interface OGBox: OGWidget
+ box;

- (void)appendChild: (OGWidget*)child
	     expand: (BOOL)expand
	       fill: (BOOL)fill
	    padding: (float)padding;
- (void)prependChild: (OGWidget*)child
	      expand: (BOOL)expand
		fill: (BOOL)fill

Added headers/OGComboBox.h version [76d02527c0].























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#import "OGWidget.h"
#import "OGComboBoxItem.h"

@class OGComboBox;

@protocol OGComboBoxDelegate <OFObject>
@optional
- (void)comboBoxWasChanged: (OGComboBox*)comboBox;
@end

@protocol OGComboBoxDataSource <OFObject>
- (size_t)numberOfItemsInComboBox: (OGComboBox*)comboBox;
- (OGComboBoxItem*)comboBox: (OGComboBox*)comboBox
		itemAtIndex: (size_t)index;
@end

@interface OGComboBox: OGWidget
{
	id <OGComboBoxDelegate> delegate;
	id <OGComboBoxDataSource> dataSource;
}

@property (assign) id <OGComboBoxDelegate> delegate;
@property (assign) id <OGComboBoxDataSource> dataSource;

+ comboBox;
@end

Added headers/OGComboBoxItem.h version [34922abd90].

























>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
#import <ObjFW/OFString.h>

@interface OGComboBoxItem: OFObject
{
	OFString *label;
}

@property (copy) OFString *label;

+ comboBoxItemWithLabel: (OFString*)label;
- initWithLabel: (OFString*)label;
@end