2008-08-02 18:31:32 +04:00
|
|
|
/*
|
2009-04-15 02:36:57 +04:00
|
|
|
* Copyright 2008,2009 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2008-08-02 18:31:32 +04:00
|
|
|
*
|
|
|
|
* 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 "desktop/tree.h"
|
2008-09-28 00:55:11 +04:00
|
|
|
#include <proto/listbrowser.h>
|
|
|
|
#include <proto/window.h>
|
|
|
|
#include <proto/layout.h>
|
|
|
|
#include <classes/window.h>
|
|
|
|
#include <gadgets/listbrowser.h>
|
|
|
|
#include <gadgets/layout.h>
|
|
|
|
#include <reaction/reaction_macros.h>
|
|
|
|
#include "amiga/gui.h"
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <proto/intuition.h>
|
|
|
|
#include "amiga/tree.h"
|
2008-10-12 01:38:04 +04:00
|
|
|
#include <proto/button.h>
|
|
|
|
#include <gadgets/button.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "utils/messages.h"
|
2008-10-19 17:01:01 +04:00
|
|
|
#include <proto/bitmap.h>
|
|
|
|
#include <images/bitmap.h>
|
2008-09-28 00:55:11 +04:00
|
|
|
|
2009-04-15 02:36:57 +04:00
|
|
|
struct Node *selectednode;
|
|
|
|
struct node *selectednode2;
|
|
|
|
|
2008-09-28 00:55:11 +04:00
|
|
|
void ami_add_elements(struct treeview_window *twin,struct node *root,WORD *gen);
|
2008-09-28 17:55:40 +04:00
|
|
|
bool ami_tree_launch_node(struct tree *tree, struct node *node);
|
|
|
|
void free_browserlist(struct List *list);
|
2008-10-14 02:34:54 +04:00
|
|
|
void ami_move_node(struct treeview_window *twin,int move);
|
2008-10-12 01:38:04 +04:00
|
|
|
void ami_new_bookmark(struct treeview_window *twin);
|
|
|
|
void ami_recreate_listbrowser(struct treeview_window *twin);
|
2008-08-02 18:31:32 +04:00
|
|
|
|
|
|
|
void tree_initialise_redraw(struct tree *tree)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tree_redraw_area(struct tree *tree, int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tree_draw_line(int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tree_draw_node_element(struct tree *tree, struct node_element *element)
|
|
|
|
{
|
2008-10-12 01:38:04 +04:00
|
|
|
return;
|
|
|
|
#if 0
|
2008-09-28 00:55:11 +04:00
|
|
|
/* add element to listbrowser list */
|
|
|
|
|
|
|
|
struct Node *lbnode;
|
|
|
|
struct treeview_window *twin = tree->handle;
|
|
|
|
struct node *tempnode;
|
|
|
|
int generation=1;
|
|
|
|
BOOL edit = FALSE;
|
|
|
|
|
|
|
|
tempnode = element->parent;
|
|
|
|
edit = tempnode->editable;
|
|
|
|
|
|
|
|
while(tempnode)
|
|
|
|
{
|
|
|
|
tempnode = tempnode->parent;
|
|
|
|
generation++;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (element->type) {
|
|
|
|
case NODE_ELEMENT_TEXT_PLUS_SPRITE:
|
|
|
|
case NODE_ELEMENT_TEXT:
|
|
|
|
if (lbnode = AllocListBrowserNode(3,
|
|
|
|
// LBNA_UserData,nodetime,
|
|
|
|
LBNA_Generation,1,
|
|
|
|
LBNA_Column, 0,
|
|
|
|
LBNCA_CopyText,TRUE,
|
|
|
|
LBNCA_Text, element->text,
|
|
|
|
LBNCA_Editable,edit,
|
|
|
|
LBNA_Column, 1,
|
|
|
|
LBNCA_CopyText,TRUE,
|
|
|
|
LBNCA_Text, "",
|
|
|
|
LBNA_Column, 2,
|
|
|
|
LBNCA_CopyText,TRUE,
|
|
|
|
LBNCA_Text, "",
|
|
|
|
TAG_DONE))
|
|
|
|
{
|
|
|
|
AddTail(twin->listbrowser_list, lbnode);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-10-12 01:38:04 +04:00
|
|
|
#endif
|
2008-08-02 18:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void tree_draw_node_expansion(struct tree *tree, struct node *node)
|
|
|
|
{
|
2008-10-12 01:38:04 +04:00
|
|
|
DebugPrintF("tree_draw_node_expansion\n");
|
2008-08-02 18:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void tree_recalculate_node_element(struct node_element *element)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tree_update_URL_node(struct node *node, const char *url,
|
|
|
|
const struct url_data *data)
|
|
|
|
{
|
2008-09-28 00:55:11 +04:00
|
|
|
struct node_element *element;
|
|
|
|
char buffer[256];
|
|
|
|
|
|
|
|
assert(node);
|
|
|
|
|
|
|
|
element = tree_find_element(node, TREE_ELEMENT_URL);
|
2008-10-13 22:00:44 +04:00
|
|
|
|
2008-09-28 00:55:11 +04:00
|
|
|
if (!element)
|
|
|
|
return;
|
|
|
|
if (data) {
|
|
|
|
/* node is linked, update */
|
|
|
|
assert(!node->editable);
|
|
|
|
if (!data->title)
|
|
|
|
urldb_set_url_title(url, url);
|
|
|
|
|
|
|
|
if (!data->title)
|
|
|
|
return;
|
|
|
|
|
|
|
|
node->data.text = data->title;
|
|
|
|
} else {
|
|
|
|
/* node is not linked, find data */
|
|
|
|
assert(node->editable);
|
|
|
|
data = urldb_get_url_data(element->text);
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not implemented yet
|
|
|
|
if (element) {
|
|
|
|
sprintf(buffer, "small_%.3x", ro_content_filetype_from_type(data->type));
|
|
|
|
if (ro_gui_wimp_sprite_exists(buffer))
|
|
|
|
tree_set_node_sprite(node, buffer, buffer);
|
|
|
|
else
|
|
|
|
tree_set_node_sprite(node, "small_xxx", "small_xxx");
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
element = tree_find_element(node, TREE_ELEMENT_LAST_VISIT);
|
|
|
|
if (element) {
|
2008-10-12 01:38:04 +04:00
|
|
|
snprintf(buffer, 256, (char *)messages_get("TreeLast"),
|
2008-09-28 00:55:11 +04:00
|
|
|
(data->last_visit > 0) ?
|
|
|
|
ctime((time_t *)&data->last_visit) :
|
2008-10-12 01:38:04 +04:00
|
|
|
(char *)messages_get("TreeUnknown"));
|
2008-09-28 00:55:11 +04:00
|
|
|
if (data->last_visit > 0)
|
|
|
|
buffer[strlen(buffer) - 1] = '\0';
|
|
|
|
free((void *)element->text);
|
2008-10-12 01:38:04 +04:00
|
|
|
element->text = (char *)strdup(buffer);
|
2008-09-28 00:55:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
element = tree_find_element(node, TREE_ELEMENT_VISITS);
|
|
|
|
if (element) {
|
2008-10-12 01:38:04 +04:00
|
|
|
snprintf(buffer, 256, (char *)messages_get("TreeVisits"),
|
2008-09-28 00:55:11 +04:00
|
|
|
data->visits);
|
|
|
|
free((void *)element->text);
|
2008-10-12 01:38:04 +04:00
|
|
|
element->text = (char *)strdup(buffer);
|
2008-09-28 00:55:11 +04:00
|
|
|
}
|
2008-08-02 18:31:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void tree_resized(struct tree *tree)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tree_set_node_sprite_folder(struct node *node)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tree_set_node_sprite(struct node *node, const char *sprite,
|
|
|
|
const char *expanded)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-10-12 01:38:04 +04:00
|
|
|
void ami_open_tree(struct tree *tree,int type)
|
2008-09-28 00:55:11 +04:00
|
|
|
{
|
|
|
|
struct treeview_window *twin;
|
2008-10-13 22:00:44 +04:00
|
|
|
BOOL msel = TRUE,nothl = TRUE,launchdisable=FALSE;
|
2008-09-28 00:55:11 +04:00
|
|
|
static WORD gen=0;
|
2008-10-12 01:38:04 +04:00
|
|
|
char *wintitle;
|
2008-10-19 17:01:01 +04:00
|
|
|
char folderclosed[100],folderopen[100],item[100];
|
2008-09-28 17:55:40 +04:00
|
|
|
|
|
|
|
if(tree->handle)
|
|
|
|
{
|
2008-10-12 01:38:04 +04:00
|
|
|
twin = (struct treeview_window *)tree->handle;
|
2008-09-28 17:55:40 +04:00
|
|
|
WindowToFront(twin->win);
|
|
|
|
ActivateWindow(twin->win);
|
|
|
|
return;
|
|
|
|
}
|
2008-09-28 00:55:11 +04:00
|
|
|
|
2008-11-02 03:21:49 +03:00
|
|
|
twin = AllocVec(sizeof(struct treeview_window),MEMF_PRIVATE | MEMF_CLEAR);
|
|
|
|
twin->listbrowser_list = AllocVec(sizeof(struct List),MEMF_PRIVATE | MEMF_CLEAR);
|
2008-09-28 00:55:11 +04:00
|
|
|
|
|
|
|
static struct ColumnInfo columninfo[] =
|
|
|
|
{
|
2008-10-13 22:00:44 +04:00
|
|
|
{ 80,"Name", CIF_DRAGGABLE | CIF_SORTABLE},
|
|
|
|
{ 20,"URL", CIF_DRAGGABLE },
|
2008-10-12 01:38:04 +04:00
|
|
|
// { 5,"Visits", CIF_DRAGGABLE },
|
2008-09-28 00:55:11 +04:00
|
|
|
{ -1, (STRPTR)~0, -1 }
|
|
|
|
};
|
|
|
|
|
|
|
|
if(tree->single_selection) msel = FALSE;
|
|
|
|
|
2008-10-19 17:01:01 +04:00
|
|
|
ami_get_theme_filename(&folderclosed,"theme_list_folder_closed");
|
|
|
|
ami_get_theme_filename(&folderopen,"theme_list_folder_open");
|
|
|
|
|
2008-10-12 01:38:04 +04:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case AMI_TREE_HOTLIST:
|
|
|
|
nothl = FALSE;
|
|
|
|
wintitle = (char *)messages_get("Hotlist");
|
2008-10-19 17:01:01 +04:00
|
|
|
ami_get_theme_filename(&item,"theme_list_bookmark");
|
2008-10-12 01:38:04 +04:00
|
|
|
break;
|
|
|
|
case AMI_TREE_COOKIES:
|
|
|
|
nothl = TRUE;
|
2008-10-13 22:00:44 +04:00
|
|
|
launchdisable=TRUE;
|
2008-10-12 01:38:04 +04:00
|
|
|
wintitle = (char *)messages_get("Cookies");
|
2008-10-19 17:01:01 +04:00
|
|
|
ami_get_theme_filename(&item,"theme_list_cookie");
|
2008-10-12 01:38:04 +04:00
|
|
|
break;
|
|
|
|
case AMI_TREE_HISTORY:
|
|
|
|
nothl = TRUE;
|
2008-10-13 22:00:44 +04:00
|
|
|
wintitle = (char *)messages_get("GlobalHistory");
|
2008-10-19 17:01:01 +04:00
|
|
|
ami_get_theme_filename(&item,"theme_list_history");
|
2008-10-12 01:38:04 +04:00
|
|
|
break;
|
2009-06-01 02:12:42 +04:00
|
|
|
case AMI_TREE_SSLCERT:
|
|
|
|
nothl = TRUE;
|
2009-06-02 01:23:14 +04:00
|
|
|
wintitle = (char *)messages_get("SSLCerts");
|
2009-06-01 02:12:42 +04:00
|
|
|
ami_get_theme_filename(&item,"theme_list_sslcert");
|
|
|
|
break;
|
2008-10-12 01:38:04 +04:00
|
|
|
}
|
|
|
|
|
2008-09-28 00:55:11 +04:00
|
|
|
NewList(twin->listbrowser_list);
|
|
|
|
|
|
|
|
tree->handle = (void *)twin;
|
|
|
|
twin->tree = tree;
|
|
|
|
ami_add_elements(twin,twin->tree->root,&gen);
|
|
|
|
|
|
|
|
twin->objects[OID_MAIN] = WindowObject,
|
|
|
|
WA_ScreenTitle,nsscreentitle,
|
2008-10-12 01:38:04 +04:00
|
|
|
WA_Title,wintitle,
|
2008-09-28 00:55:11 +04:00
|
|
|
WA_Activate, TRUE,
|
|
|
|
WA_DepthGadget, TRUE,
|
|
|
|
WA_DragBar, TRUE,
|
|
|
|
WA_CloseGadget, TRUE,
|
|
|
|
WA_SizeGadget, TRUE,
|
|
|
|
WA_CustomScreen,scrn,
|
2008-09-28 17:55:40 +04:00
|
|
|
WINDOW_SharedPort,sport,
|
|
|
|
WINDOW_UserData,twin,
|
2008-09-28 00:55:11 +04:00
|
|
|
WINDOW_IconifyGadget, TRUE,
|
2008-10-12 01:38:04 +04:00
|
|
|
WINDOW_Position, WPOS_CENTERSCREEN,
|
|
|
|
WINDOW_ParentGroup, twin->gadgets[GID_MAIN] = VGroupObject,
|
2008-09-28 00:55:11 +04:00
|
|
|
LAYOUT_AddChild, twin->gadgets[GID_TREEBROWSER] = ListBrowserObject,
|
2008-10-13 22:00:44 +04:00
|
|
|
GA_ID, GID_TREEBROWSER,
|
|
|
|
GA_RelVerify, TRUE,
|
2008-09-28 00:55:11 +04:00
|
|
|
GA_ReadOnly,FALSE,
|
|
|
|
LISTBROWSER_ColumnInfo, &columninfo,
|
2008-10-12 01:38:04 +04:00
|
|
|
// LISTBROWSER_ColumnTitles, TRUE,
|
2008-09-28 00:55:11 +04:00
|
|
|
LISTBROWSER_Hierarchical,TRUE,
|
2008-09-28 17:55:40 +04:00
|
|
|
LISTBROWSER_Editable,TRUE,
|
2008-09-28 00:55:11 +04:00
|
|
|
// LISTBROWSER_TitleClickable,TRUE,
|
|
|
|
LISTBROWSER_AutoFit, TRUE,
|
|
|
|
LISTBROWSER_HorizontalProp, TRUE,
|
|
|
|
LISTBROWSER_Labels, twin->listbrowser_list,
|
2008-10-12 01:38:04 +04:00
|
|
|
// LISTBROWSER_MultiSelect,msel,
|
2008-09-28 17:55:40 +04:00
|
|
|
LISTBROWSER_ShowSelected,TRUE,
|
2008-10-19 17:01:01 +04:00
|
|
|
LISTBROWSER_ShowImage,BitMapObject,
|
|
|
|
BITMAP_SourceFile,folderclosed,
|
|
|
|
BITMAP_Screen,scrn,
|
|
|
|
BITMAP_Masking,TRUE,
|
|
|
|
BitMapEnd,
|
|
|
|
LISTBROWSER_HideImage,BitMapObject,
|
|
|
|
BITMAP_SourceFile,folderopen,
|
|
|
|
BITMAP_Screen,scrn,
|
|
|
|
BITMAP_Masking,TRUE,
|
|
|
|
BitMapEnd,
|
|
|
|
LISTBROWSER_LeafImage,BitMapObject,
|
|
|
|
BITMAP_SourceFile,item,
|
|
|
|
BITMAP_Screen,scrn,
|
|
|
|
BITMAP_Masking,TRUE,
|
|
|
|
BitMapEnd,
|
2008-10-12 01:38:04 +04:00
|
|
|
ListBrowserEnd,
|
2008-09-28 00:55:11 +04:00
|
|
|
CHILD_NominalSize,TRUE,
|
2008-10-12 01:38:04 +04:00
|
|
|
LAYOUT_AddChild, HGroupObject,
|
|
|
|
LAYOUT_AddChild, twin->gadgets[GID_OPEN] = ButtonObject,
|
|
|
|
GA_ID,GID_OPEN,
|
2008-10-13 22:00:44 +04:00
|
|
|
GA_Text,messages_get("TreeLaunch"),
|
2008-10-12 01:38:04 +04:00
|
|
|
GA_RelVerify,TRUE,
|
2008-10-13 22:00:44 +04:00
|
|
|
GA_Disabled,launchdisable,
|
2008-10-12 01:38:04 +04:00
|
|
|
ButtonEnd,
|
|
|
|
LAYOUT_AddChild, twin->gadgets[GID_NEWF] = ButtonObject,
|
|
|
|
GA_ID,GID_NEWF,
|
|
|
|
BUTTON_AutoButton,BAG_POPDRAWER,
|
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
GA_Disabled,nothl,
|
|
|
|
ButtonEnd,
|
|
|
|
LAYOUT_AddChild, twin->gadgets[GID_NEWB] = ButtonObject,
|
|
|
|
GA_ID,GID_NEWB,
|
|
|
|
BUTTON_AutoButton,BAG_POPFILE,
|
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
GA_Disabled,nothl,
|
|
|
|
ButtonEnd,
|
2008-10-14 02:34:54 +04:00
|
|
|
LAYOUT_AddChild, twin->gadgets[GID_LEFT] = ButtonObject,
|
|
|
|
GA_ID,GID_LEFT,
|
|
|
|
BUTTON_AutoButton,BAG_LFARROW,
|
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
GA_Disabled,nothl, //(!tree->movable),
|
|
|
|
ButtonEnd,
|
2008-10-12 01:38:04 +04:00
|
|
|
LAYOUT_AddChild, twin->gadgets[GID_UP] = ButtonObject,
|
|
|
|
GA_ID,GID_UP,
|
|
|
|
BUTTON_AutoButton,BAG_UPARROW,
|
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
GA_Disabled,nothl, //(!tree->movable),
|
|
|
|
ButtonEnd,
|
|
|
|
LAYOUT_AddChild, twin->gadgets[GID_DOWN] = ButtonObject,
|
|
|
|
GA_ID,GID_DOWN,
|
|
|
|
BUTTON_AutoButton,BAG_DNARROW,
|
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
GA_Disabled,nothl, //(!tree->movable),
|
|
|
|
ButtonEnd,
|
|
|
|
LAYOUT_AddChild, twin->gadgets[GID_DEL] = ButtonObject,
|
|
|
|
GA_ID,GID_DEL,
|
2008-10-13 22:00:44 +04:00
|
|
|
GA_Text,messages_get("TreeDelete"),
|
2008-10-12 01:38:04 +04:00
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
ButtonEnd,
|
|
|
|
EndGroup,
|
|
|
|
CHILD_WeightedHeight,0,
|
2008-09-28 00:55:11 +04:00
|
|
|
EndGroup,
|
|
|
|
EndWindow;
|
|
|
|
|
|
|
|
twin->win = (struct Window *)RA_OpenWindow(twin->objects[OID_MAIN]);
|
|
|
|
|
|
|
|
twin->node = AddObject(window_list,AMINS_TVWINDOW);
|
|
|
|
twin->node->objstruct = twin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Launches a node using all known methods.
|
|
|
|
*
|
|
|
|
* \param node the node to launch
|
|
|
|
* \return whether the node could be launched
|
|
|
|
*/
|
|
|
|
bool ami_tree_launch_node(struct tree *tree, struct node *node)
|
|
|
|
{
|
|
|
|
struct node_element *element;
|
|
|
|
|
|
|
|
assert(node);
|
|
|
|
|
|
|
|
element = tree_find_element(node, TREE_ELEMENT_URL);
|
|
|
|
if (element) {
|
|
|
|
browser_window_create(element->text, NULL, 0, true, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not implemented yet
|
|
|
|
element = tree_find_element(node, TREE_ELEMENT_SSL);
|
|
|
|
if (element) {
|
|
|
|
ro_gui_cert_open(tree, node);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-28 17:55:40 +04:00
|
|
|
void ami_tree_close(struct treeview_window *twin)
|
2008-09-28 00:55:11 +04:00
|
|
|
{
|
2008-10-12 01:38:04 +04:00
|
|
|
twin->tree->handle = 0;
|
2008-09-28 00:55:11 +04:00
|
|
|
DisposeObject(twin->objects[OID_MAIN]);
|
|
|
|
FreeListBrowserList(twin->listbrowser_list);
|
2008-09-28 17:55:40 +04:00
|
|
|
FreeVec(twin->listbrowser_list);
|
2008-09-28 00:55:11 +04:00
|
|
|
//free_browserlist(twin->listbrowser_list);
|
|
|
|
DelObject(twin->node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_browserlist(struct List *list)
|
|
|
|
{
|
|
|
|
struct Node *node, *nextnode;
|
|
|
|
|
|
|
|
if(IsListEmpty(list)) return;
|
|
|
|
|
2008-10-06 22:20:16 +04:00
|
|
|
node = GetHead(list);
|
|
|
|
|
|
|
|
do
|
2008-09-28 00:55:11 +04:00
|
|
|
{
|
2008-10-06 22:20:16 +04:00
|
|
|
nextnode = GetSucc(node);
|
2008-10-12 01:38:04 +04:00
|
|
|
// FreeVec(node->ln_Name);
|
2008-09-28 00:55:11 +04:00
|
|
|
FreeListBrowserNode(node);
|
2008-10-06 22:20:16 +04:00
|
|
|
} while(node = nextnode);
|
2008-09-28 00:55:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ami_add_elements(struct treeview_window *twin,struct node *root,WORD *gen)
|
|
|
|
{
|
|
|
|
struct Node *lbnode;
|
|
|
|
struct tree *tree = twin->tree;
|
|
|
|
struct node *tempnode;
|
|
|
|
int generation=1;
|
|
|
|
BOOL edit = FALSE;
|
|
|
|
struct node_element *element=NULL,*element2=NULL,*element3=NULL;
|
|
|
|
struct node *node;
|
2008-09-28 17:55:40 +04:00
|
|
|
ULONG flags = 0;
|
|
|
|
STRPTR text1 = "",text2 = "",text3 = "";
|
2008-09-28 00:55:11 +04:00
|
|
|
|
|
|
|
*gen = *gen + 1;
|
|
|
|
for (node = root; node; node = node->next)
|
|
|
|
{
|
|
|
|
element = tree_find_element(node, TREE_ELEMENT_NAME);
|
|
|
|
if(!element) element = tree_find_element(node, TREE_ELEMENT_TITLE);
|
2009-06-01 02:12:42 +04:00
|
|
|
if(!element) element = tree_find_element(node, TREE_ELEMENT_SSL);
|
2008-09-28 17:55:40 +04:00
|
|
|
if(element && element->text)
|
|
|
|
{
|
2008-10-12 01:38:04 +04:00
|
|
|
text1 = (char *)element->text;
|
2008-09-28 17:55:40 +04:00
|
|
|
}
|
|
|
|
|
2008-10-12 01:38:04 +04:00
|
|
|
/* Really, the second column needs axing - relevant data should appear in an
|
|
|
|
area below the listview when items are selected */
|
|
|
|
|
2008-09-28 00:55:11 +04:00
|
|
|
element2 = tree_find_element(node, TREE_ELEMENT_URL);
|
2008-10-12 01:38:04 +04:00
|
|
|
if(!element2) element2 = tree_find_element(node, TREE_ELEMENT_VALUE);
|
|
|
|
if(!element2) element2 = tree_find_element(node, TREE_ELEMENT_COMMENT);
|
2008-09-28 17:55:40 +04:00
|
|
|
|
|
|
|
if(element2 && element2->text)
|
|
|
|
{
|
2008-10-12 01:38:04 +04:00
|
|
|
text2 = (char *)element2->text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text2 = "";
|
2008-09-28 17:55:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// element = tree_find_element(node, TREE_ELEMENT_VISITS);
|
|
|
|
|
2008-10-13 22:00:44 +04:00
|
|
|
flags = 0;
|
|
|
|
/*if(node->expanded) */ flags = LBFLG_SHOWCHILDREN;
|
|
|
|
if(node->folder) flags |= LBFLG_HASCHILDREN;
|
|
|
|
if(!node->parent) flags |= LBFLG_HIDDEN;
|
2008-09-28 00:55:11 +04:00
|
|
|
|
|
|
|
switch (element->type) {
|
|
|
|
case NODE_ELEMENT_TEXT_PLUS_SPRITE:
|
|
|
|
case NODE_ELEMENT_TEXT:
|
|
|
|
if (lbnode = AllocListBrowserNode(3,
|
2008-09-28 17:55:40 +04:00
|
|
|
LBNA_UserData,node,
|
2008-10-13 22:00:44 +04:00
|
|
|
LBNA_Generation,*gen - 1,
|
2008-09-28 17:55:40 +04:00
|
|
|
LBNA_Selected,node->selected,
|
|
|
|
LBNA_Flags,flags,
|
2008-09-28 00:55:11 +04:00
|
|
|
LBNA_Column, 0,
|
2008-09-28 17:55:40 +04:00
|
|
|
LBNCA_CopyText,TRUE,
|
|
|
|
LBNCA_MaxChars,256,
|
|
|
|
LBNCA_Text, text1,
|
|
|
|
LBNCA_Editable,node->editable,
|
|
|
|
LBNA_Column, 1,
|
|
|
|
LBNCA_CopyText,TRUE,
|
|
|
|
LBNCA_MaxChars,256,
|
|
|
|
LBNCA_Text, text2,
|
2008-10-12 01:38:04 +04:00
|
|
|
LBNCA_Editable,FALSE,
|
2008-09-28 17:55:40 +04:00
|
|
|
TAG_DONE))
|
2008-09-28 00:55:11 +04:00
|
|
|
{
|
|
|
|
AddTail(twin->listbrowser_list, lbnode);
|
2009-04-15 02:36:57 +04:00
|
|
|
if(node == selectednode2) selectednode = lbnode;
|
2008-09-28 00:55:11 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->child)
|
|
|
|
{
|
|
|
|
ami_add_elements(twin,node->child,gen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*gen = *gen - 1;
|
|
|
|
}
|
2008-09-28 17:55:40 +04:00
|
|
|
|
|
|
|
BOOL ami_tree_event(struct treeview_window *twin)
|
|
|
|
{
|
|
|
|
/* return TRUE if window destroyed */
|
|
|
|
ULONG class,result,relevent = 0;
|
2008-10-12 01:38:04 +04:00
|
|
|
ULONG column;
|
2008-09-28 17:55:40 +04:00
|
|
|
uint16 code;
|
|
|
|
struct MenuItem *item;
|
|
|
|
struct node *treenode;
|
|
|
|
struct Node *lbnode;
|
2008-10-12 01:38:04 +04:00
|
|
|
struct node_element *element;
|
|
|
|
char *text;
|
|
|
|
// ULONG editcols[] = {TREE_ELEMENT_TITLE,TREE_ELEMENT_URL};
|
|
|
|
static WORD gen=0;
|
2008-09-28 17:55:40 +04:00
|
|
|
|
|
|
|
while((result = RA_HandleInput(twin->objects[OID_MAIN],&code)) != WMHI_LASTMSG)
|
|
|
|
{
|
|
|
|
switch(result & WMHI_CLASSMASK) // class
|
|
|
|
{
|
|
|
|
case WMHI_GADGETUP:
|
|
|
|
switch(result & WMHI_GADGETMASK)
|
|
|
|
{
|
|
|
|
case GID_TREEBROWSER:
|
|
|
|
GetAttrs(twin->gadgets[GID_TREEBROWSER],
|
|
|
|
LISTBROWSER_RelEvent,&relevent,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
switch(relevent)
|
|
|
|
{
|
|
|
|
case LBRE_DOUBLECLICK:
|
|
|
|
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
|
|
|
TAG_DONE);
|
|
|
|
ami_tree_launch_node(twin->tree,treenode);
|
|
|
|
break;
|
2008-10-12 01:38:04 +04:00
|
|
|
|
|
|
|
case LBRE_EDIT:
|
|
|
|
GetAttrs(twin->gadgets[GID_TREEBROWSER],
|
|
|
|
LISTBROWSER_SelectedNode,(ULONG *)&lbnode,
|
|
|
|
// LISTBROWSER_RelColumn,(ULONG *)&column,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
element = tree_find_element(treenode,TREE_ELEMENT_TITLE);
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_Column,column,
|
|
|
|
LBNCA_Text,(ULONG *)&text,
|
|
|
|
TAG_DONE);
|
|
|
|
element->text = (char *)strdup(text);
|
|
|
|
tree_handle_node_element_changed(twin->tree, element);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LBRE_HIDECHILDREN:
|
|
|
|
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
|
|
|
TAG_DONE);
|
|
|
|
tree_set_node_expanded(twin->tree, treenode, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LBRE_SHOWCHILDREN:
|
|
|
|
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
|
|
|
TAG_DONE);
|
|
|
|
tree_set_node_expanded(twin->tree, treenode, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GID_OPEN:
|
|
|
|
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
|
|
|
TAG_DONE);
|
|
|
|
ami_tree_launch_node(twin->tree,treenode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GID_NEWF:
|
|
|
|
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
|
|
|
|
if(lbnode)
|
|
|
|
{
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
|
|
|
TAG_DONE);
|
2008-09-28 17:55:40 +04:00
|
|
|
}
|
2008-10-12 01:38:04 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
treenode = twin->tree->root;
|
|
|
|
}
|
|
|
|
|
|
|
|
tree_create_folder_node(treenode,(char *)messages_get("TreeNewFolder"));
|
|
|
|
|
|
|
|
ami_recreate_listbrowser(twin);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GID_NEWB:
|
|
|
|
ami_new_bookmark(twin);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GID_UP:
|
2008-10-14 02:34:54 +04:00
|
|
|
ami_move_node(twin,AMI_MOVE_UP);
|
2008-10-12 01:38:04 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GID_DOWN:
|
2008-10-14 02:34:54 +04:00
|
|
|
ami_move_node(twin,AMI_MOVE_DOWN);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GID_LEFT:
|
|
|
|
ami_move_node(twin,AMI_MOVE_OUT);
|
2008-10-12 01:38:04 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GID_DEL:
|
|
|
|
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
|
|
|
TAG_DONE);
|
2008-10-12 03:06:18 +04:00
|
|
|
tree_delete_node(twin->tree, treenode, false);
|
2008-10-12 01:38:04 +04:00
|
|
|
/* We are recreating the list from scratch as there is no obvious easy way
|
|
|
|
to delete children from a listbrowser list */
|
|
|
|
ami_recreate_listbrowser(twin);
|
2008-09-28 17:55:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* no menus yet, copied in as will probably need it later
|
|
|
|
case WMHI_MENUPICK:
|
|
|
|
item = ItemAddress(gwin->win->MenuStrip,code);
|
|
|
|
while (code != MENUNULL)
|
|
|
|
{
|
|
|
|
ami_menupick(code,gwin);
|
|
|
|
if(win_destroyed) break;
|
|
|
|
code = item->NextSelect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
|
|
|
|
case WMHI_CLOSEWINDOW:
|
|
|
|
ami_tree_close(twin);
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-12 01:38:04 +04:00
|
|
|
|
2008-10-14 02:34:54 +04:00
|
|
|
void ami_move_node(struct treeview_window *twin,int move)
|
2008-10-12 01:38:04 +04:00
|
|
|
{
|
|
|
|
struct Node *lbnode = NULL;
|
2008-10-13 22:00:44 +04:00
|
|
|
struct node *treenode,*moveto;
|
2008-10-14 02:34:54 +04:00
|
|
|
bool before;
|
2008-10-12 01:38:04 +04:00
|
|
|
|
|
|
|
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
|
|
|
|
|
2008-10-14 02:34:54 +04:00
|
|
|
if(!lbnode) return;
|
|
|
|
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
2008-10-13 22:00:44 +04:00
|
|
|
// for multiselects? LBNA_Selected,(BOOL *)&sel,
|
2008-10-14 02:34:54 +04:00
|
|
|
TAG_DONE);
|
2008-10-12 01:38:04 +04:00
|
|
|
|
2009-04-15 02:36:57 +04:00
|
|
|
selectednode2 = treenode;
|
|
|
|
|
2008-10-14 02:34:54 +04:00
|
|
|
tree_set_node_selected(twin->tree,twin->tree->root,false);
|
2008-10-13 22:00:44 +04:00
|
|
|
tree_set_node_selected(twin->tree,treenode,true);
|
2008-10-12 01:38:04 +04:00
|
|
|
|
2008-10-14 02:34:54 +04:00
|
|
|
switch(move)
|
2008-10-13 22:00:44 +04:00
|
|
|
{
|
2008-10-14 02:34:54 +04:00
|
|
|
case AMI_MOVE_UP:
|
|
|
|
moveto = treenode->previous;
|
|
|
|
before = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AMI_MOVE_DOWN:
|
|
|
|
moveto = treenode->next;
|
|
|
|
before = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AMI_MOVE_OUT:
|
|
|
|
moveto = treenode->parent->previous;
|
|
|
|
before = false;
|
|
|
|
break;
|
2008-10-12 01:38:04 +04:00
|
|
|
}
|
|
|
|
|
2008-10-14 02:34:54 +04:00
|
|
|
if(!moveto) return;
|
|
|
|
|
|
|
|
tree_delink_node(treenode);
|
|
|
|
//tree_move_selected_nodes(twin->tree,moveto,before);
|
|
|
|
tree_link_node(moveto,treenode,before);
|
2008-10-12 01:38:04 +04:00
|
|
|
ami_recreate_listbrowser(twin);
|
2009-04-15 02:36:57 +04:00
|
|
|
selectednode2 = NULL;
|
2008-10-12 01:38:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ami_new_bookmark(struct treeview_window *twin)
|
|
|
|
{
|
|
|
|
const struct url_data *data;
|
|
|
|
struct Node *lbnode;
|
|
|
|
struct node *treenode;
|
|
|
|
char *url,*title;
|
|
|
|
|
|
|
|
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
|
|
|
|
if(lbnode)
|
|
|
|
{
|
|
|
|
GetListBrowserNodeAttrs(lbnode,
|
|
|
|
LBNA_UserData,(ULONG *)&treenode,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
treenode = twin->tree->root;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = (char *)strdup("http://www.netsurf-browser.org");
|
|
|
|
|
|
|
|
data = urldb_get_url_data(url);
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
urldb_add_url(url);
|
|
|
|
urldb_set_url_persistence(url,true);
|
|
|
|
data = urldb_get_url_data(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
2008-10-13 22:00:44 +04:00
|
|
|
title = data->title;
|
2008-10-12 01:38:04 +04:00
|
|
|
tree_create_URL_node(treenode,url,data,title);
|
|
|
|
ami_recreate_listbrowser(twin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ami_recreate_listbrowser(struct treeview_window *twin)
|
|
|
|
{
|
|
|
|
static WORD gen=0;
|
|
|
|
|
|
|
|
SetGadgetAttrs(twin->gadgets[GID_TREEBROWSER],twin->win,NULL,
|
|
|
|
LISTBROWSER_Labels,~0,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
FreeListBrowserList(twin->listbrowser_list);
|
|
|
|
ami_add_elements(twin,twin->tree->root,&gen);
|
|
|
|
|
|
|
|
RefreshSetGadgetAttrs(twin->gadgets[GID_TREEBROWSER],twin->win,NULL,
|
|
|
|
LISTBROWSER_Labels,twin->listbrowser_list,
|
2009-04-15 02:36:57 +04:00
|
|
|
LISTBROWSER_SelectedNode,selectednode,
|
2008-10-12 01:38:04 +04:00
|
|
|
TAG_DONE);
|
|
|
|
}
|