summaryrefslogtreecommitdiff
path: root/atari/history.c
blob: aa32cbf7e704d69cc7c020bacc8724b8ae25853b (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright 2010 Ole Loots <ole@monochrom.net>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf 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 <http://www.gnu.org/licenses/>.
 */

#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "desktop/browser.h"
#include "desktop/options.h"
#include "desktop/tree.h"
#include "desktop/tree_url_node.h"
#include "desktop/gui.h"
#include "desktop/history_global_core.h"
#include "desktop/browser.h"
#include "utils/messages.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "content/urldb.h"
#include "utils/log.h"
#include "atari/treeview.h"
#include "atari/findfile.h"
#include "atari/res/netsurf.rsh"
#include "atari/history.h"


//TODO: remove/add guiwin handle on close / open - so that the list
// is kept tiny.

extern char * tree_directory_icon_name;
extern GRECT desk_area;

struct s_atari_global_history gl_history;


void global_history_open( void )
{
	global_history_init();
	if (gl_history.init == false ) {
		return;
	}
	if( gl_history.open == false ) {

	    GRECT pos;
	    wind_get_grect(0, WF_WORKXYWH, &pos);
	    pos.g_x = desk_area.g_w - desk_area.g_w / 4;
	    pos.g_y = desk_area.g_y;
	    pos.g_w = desk_area.g_w / 4;
	    pos.g_h = desk_area.g_h;

		wind_open(gemtk_wm_get_handle(gl_history.window), pos.g_x, pos.g_y,
            pos.g_w, pos.g_h);
		gl_history.open = true;
		atari_treeview_open(gl_history.tv);
	} else {
		wind_set(gemtk_wm_get_handle(gl_history.window), WF_TOP, 1, 0, 0, 0);
	}
}

void global_history_close( void )
{
    wind_close(gemtk_wm_get_handle(gl_history.window));
	gl_history.open = false;
	atari_treeview_close(gl_history.tv);
}

static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
{
	NSTREEVIEW tv=NULL;

    //printf("Hotlist event %d, open: %d\n", ev_out->emo_events, gl_history.open);

	if(ev_out->emo_events & MU_MESAG){
		switch (msg[0]) {

			case WM_CLOSED:
				global_history_close();
			break;

			default: break;
		}
	}

	// TODO: implement selectable objects in toolbar API:
	// ObjcChange( OC_TOOLBAR, win, buff[4], ~SELECTED, OC_MSG );
}

bool global_history_init( void )
{

    if( gl_history.init == false ) {

        short handle;
        GRECT desk;
        int flags = ATARI_TREEVIEW_WIDGETS;

        gl_history.open = false;
        handle = wind_create(flags, 40, 40, desk_area.g_w, desk_area.g_h);
        gl_history.window = gemtk_wm_add(handle, GEMTK_WM_FLAG_DEFAULTS, NULL);
        if( gl_history.window == NULL ) {
			LOG(("Failed to allocate history window"));
			return( false );
		}
		wind_set_str(handle, WF_NAME, (char*)messages_get("GlobalHistory"));

		gl_history.tv = atari_treeview_create(history_global_get_tree_flags(),
                                        gl_history.window, handle_event);

		gemtk_wm_unlink(gl_history.window);

        if (gl_history.tv == NULL) {
            /* TODO: handle it properly, clean up previous allocs */
            LOG(("Failed to allocate history treeview"));
            return( false );
        }

        history_global_initialise(gl_history.tv->tree, "dir.png");
        gl_history.init = true;
    }
	return( true );
}


void global_history_destroy( void )
{

	if( gl_history.init == false ) {
		return;
	}
	if( gl_history.window != NULL ) {
		history_global_cleanup();
		if( gl_history.open )
			global_history_close();
		wind_delete(gemtk_wm_get_handle(gl_history.window));
		gemtk_wm_remove(gl_history.window);
		gl_history.window = NULL;
		atari_treeview_destroy(gl_history.tv);
		gl_history.init = false;
	}
	LOG(("done"));
}

void global_history_redraw( void )
{
	atari_treeview_redraw( gl_history.tv );
}